<?php

/**
 * 资本到位记录
 */
//传人基金id（基金基本信息表）
function zibendaowei_jilu_create($chuziren_id){
	  //我们为这个页面设置标题
	 drupal_set_title('新增资本到位记录');
	 
	 $page_content = l('返回列表','zibendaowei/jilu/renlist/'.$chuziren_id) . '<br />'. '<br />';
	 
	 $render_array = array(
	   '#markup' => $page_content, 
	 );
	  global $user;
	  $query = "SELECT fund_id FROM " .
           "{chuziren_info} where id = ?";
      $queryResult = db_query($query, array($chuziren_id));
	  $fund_id = '';
	  foreach($queryResult as $fund){
	  	$fund_id = $fund->fund_id;
	  }
	  $query = "SELECT id FROM " .
           "{fund_basic_information} where user_id = ?";
      $queryResult = db_query($query, array($user->uid));
      foreach ($queryResult as $result) {
    	if($result->id != $fund_id){
    		drupal_goto('zibendaowei/jilu/fund');
    	}
		
	  }
	 $form = drupal_get_form('zibendaowei_jilu_form',$chuziren_id);
	 $render_array['#markup'] .= drupal_render($form);
	 
	 return $render_array;
}

function zibendaowei_jilu_form($form, &$form_state, $chuziren_id){
	 $form['bid'] = array('#type' => 'hidden', '#value' => $chuziren_id);
	 
	 $form['tips'] = array(
	  '#prefix' =>'<div id="tips">',
	  '#markup' => t('<span class="form-required">*</span> 号为必填项。'),
	  '#suffix' =>'</div>',
	 );
	 
	 $form['round_num'] = array(
	  '#title' => t('轮次'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['zibendaowei_jilu_form']['round_num'])?$_SESSION['zibendaowei_jilu_form']['round_num']:"",
	  '#description' => t('例如：1'),
	 );
	
	 $form['amount'] = array(
	  '#title' => t('出资金额（万元）'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['zibendaowei_jilu_form']['amount'])?$_SESSION['zibendaowei_jilu_form']['amount']:"",
	  '#description' => t('例如：250.55'),
	 );
	 
	 $today = getdate();

      $form['timestamp'] = array(
	     '#type' => 'date', // types 'date_popup', 'date_text' and 'date_timezone' are also supported. See .inc file.
	     '#title' => t('出资时间'),
	     '#default_value' => array('year' =>  $today['year'], 'month' =>  $today['mon'], 'day' => $today['mday']), 
	  );
  	 
	 $form['remark'] = array(
	  '#title' => t('备注'),
	  '#type' => 'textarea',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['zibendaowei_jilu_form']['remark'])?$_SESSION['zibendaowei_jilu_form']['remark']:"",
	 );
	
	  $form['submit'] = array(
	    '#type' => 'submit',
	    '#value' => t('确认'),
	  );
	  return $form;
}

function zibendaowei_jilu_form_validate($form, &$form_state){
	  if (drupal_strlen($form_state['values']['amount']) > 15) {
	    form_set_error('amount', '要求精度小于15个字符');
	  } 
	  if (!($form_state['values']['amount']>0)) {
	    form_set_error('amount', '请输入正数');
	  } 
	  if (!($form_state['values']['round_num']>0)) {
	    form_set_error('round_num', '请输入正数');
	  } 
	 
}

function zibendaowei_jilu_form_submit($form, &$form_state){
	  //把表单的值存放在会话中去，由于这里涉及到了两个不同的表单之间传值。
	  $values= $form_state['values'];
      $datetime = mktime(0, 0, 0,$values['timestamp']['month'], $values['timestamp']['day'], $values['timestamp']['year']);
	  $query = "SELECT fund_id FROM " .
           "{chuziren_info} where id = ?";
      $queryResult = db_query($query, array($values['bid']));
	  $fund_id = '';
	  foreach($queryResult as $fund){
	  	$fund_id = $fund->fund_id;
	  }
	  	$last_id = db_insert('daoweijilu')
  		->fields(array(
  		     'fund_id' => $fund_id,
  		     'chuziren_type' => 1,
   			 'round_num' => $values['round_num'],
   			 'chuziren_id' => $values['bid'],
   			 'amount' => $values['amount'],
   			 'timestamp' =>  $datetime,
   			 'remark' => $values['remark'],
  			))->execute();
		  if ($last_id!=NULL) {
		  	  $contributed_capital = 0;
			  $query = "SELECT amount FROM {daoweijilu} WHERE fund_id = ?";
			  $queryResult = db_query($query,array($fund_id));
			  foreach($queryResult as $fund){
				  $contributed_capital += $fund->amount;
			  }
		  	  db_update('fund_basic_information')
		  		->fields(array(
		   			 'contributed_capital' => $contributed_capital,
		  			))
		  		->condition('id', $fund_id)
		  		->execute();
			 $form_state['redirect'] = 'zibendaowei/jilu/renlist/'.$values['bid'];
		  } else {
		    drupal_set_message('抱歉，遇到问题，提交失败了', 'error');    
		  }	
}

function zibendaowei_jilu_geren_create($chuziren_id){
	  //我们为这个页面设置标题
	 drupal_set_title('新增资本到位记录');
	 
	 $page_content = l('查看资本到位记录','zibendaowei/jilu/geren/'.$chuziren_id) . '<br />'. '<br />';
	 
	 $render_array = array(
	   '#markup' => $page_content, 
	 );
	  global $user;
	  $query = "SELECT fund_id FROM " .
           "{chuziren_geren_info} where id = ?";
      $queryResult = db_query($query, array($chuziren_id));
	  $fund_id = '';
	  foreach($queryResult as $fund){
	  	$fund_id = $fund->fund_id;
	  }
	  $query = "SELECT id FROM " .
           "{fund_basic_information} where user_id = ?";
      $queryResult = db_query($query, array($user->uid));
      foreach ($queryResult as $result) {
    	if($result->id != $fund_id){
    		drupal_goto('zibendaowei/jilu/ren');
    	}
		
	  }
	 $form = drupal_get_form('zibendaowei_jilu_geren_form',$chuziren_id);
	 $render_array['#markup'] .= drupal_render($form);
	 
	 return $render_array;
}

function zibendaowei_jilu_geren_form($form, &$form_state, $chuziren_id){
	 $form['bid'] = array('#type' => 'hidden', '#value' => $chuziren_id);
	 
	 $form['tips'] = array(
	  '#prefix' =>'<div id="tips">',
	  '#markup' => t('<span class="form-required">*</span> 号为必填项。'),
	  '#suffix' =>'</div>',
	 );
	 
	 $form['round_num'] = array(
	  '#title' => t('轮次'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['zibendaowei_jilu_form']['round_num'])?$_SESSION['zibendaowei_jilu_form']['round_num']:"",
	  '#description' => t('例如：1'),
	 );
	
	 $form['amount'] = array(
	  '#title' => t('出资金额（万元）'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['zibendaowei_jilu_form']['amount'])?$_SESSION['zibendaowei_jilu_form']['amount']:"",
	  '#description' => t('例如：250.55'),
	 );
	 
	 $today = getdate();

      $form['timestamp'] = array(
	     '#type' => 'date', // types 'date_popup', 'date_text' and 'date_timezone' are also supported. See .inc file.
	     '#title' => t('出资时间'),
	     '#default_value' => array('year' =>  $today['year'], 'month' =>  $today['mon'], 'day' => $today['mday']), 
	  );
  	 
	 $form['remark'] = array(
	  '#title' => t('备注'),
	  '#type' => 'textarea',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['zibendaowei_jilu_form']['remark'])?$_SESSION['zibendaowei_jilu_form']['remark']:"",
	 );
	
	  $form['submit'] = array(
	    '#type' => 'submit',
	    '#value' => t('确认'),
	  );
	  return $form;
}

function zibendaowei_jilu_geren_form_validate($form, &$form_state){
	  if (drupal_strlen($form_state['values']['amount']) > 15) {
	    form_set_error('amount', '要求精度小于15个字符');
	  } 
	  if (!($form_state['values']['amount']>0)) {
	    form_set_error('amount', '请输入正数');
	  } 
	  if (!($form_state['values']['round_num']>0)) {
	    form_set_error('round_num', '请输入正数');
	  } 
	 
}

function zibendaowei_jilu_geren_form_submit($form, &$form_state){
	  //把表单的值存放在会话中去，由于这里涉及到了两个不同的表单之间传值。
	  $values= $form_state['values'];
      $datetime = mktime(0, 0, 0,$values['timestamp']['month'], $values['timestamp']['day'], $values['timestamp']['year']);
	  $query = "SELECT fund_id FROM " .
           "{chuziren_geren_info} where id = ?";
      $queryResult = db_query($query, array($values['bid']));
	  $fund_id = '';
	  foreach($queryResult as $fund){
	  	$fund_id = $fund->fund_id;
	  }
	  	$last_id = db_insert('daoweijilu')
  		->fields(array(
  		     'fund_id' => $fund_id,
  		     'chuziren_type' => 2,
   			 'round_num' => $values['round_num'],
   			 'chuziren_id' => $values['bid'],
   			 'amount' => $values['amount'],
   			 'timestamp' =>  $datetime,
   			 'remark' => $values['remark'],
  			))->execute();
		  if ($last_id!=NULL) {
		  	$contributed_capital = 0;
			  $query = "SELECT amount FROM {daoweijilu} WHERE fund_id = ?";
			  $queryResult = db_query($query,array($fund_id));
			  foreach($queryResult as $fund){
				  $contributed_capital += $fund->amount;
			  }
		  	  db_update('fund_basic_information')
		  		->fields(array(
		   			 'contributed_capital' => $contributed_capital,
		  			))
		  		->condition('id', $fund_id)
		  		->execute();
			 $form_state['redirect'] = 'zibendaowei/jilu/geren/'.$values['bid'];
		  } else {
		    drupal_set_message('抱歉，遇到问题，提交失败了', 'error');    
		  }	
}

//传人到位记录id
function zibendaowei_jilu_view_page($perid) {
 
  // content variable that will be returned for display
  $html = '';
  
  drupal_set_title('浏览该项资本到位记录');
  $query = "SELECT fund_id, round_num,amount,timestamp,remark FROM " .
           "{daoweijilu} where id = ?";
  $queryResult = db_query($query, array($perid));
  foreach ($queryResult as $links ) {
  	$html .= l('返回列表','zibendaowei/jilu/fundlist/'.$links->fund_id) . '<br />'. '<br />';  
  	
	$html .= "<table width=\"500px\"><tr><td width=\"35%\">轮次</td><td width=\"65%\">".$links->round_num."</td></tr>
	<tr><td>出资金额</td><td>".$links->amount."</td></tr>
	<tr><td>出资时间</td><td>".format_date($links->timestamp, 'custom', 'Y-m-d')."</td></tr>
	<tr><td>备注</td><td>".$links->remark."</td></tr></table>";
  }
	
  return $html;
}

function zibendaowei_jilu_edit_page($perid) {
 
  // content variable that will be returned for display
  $page_content = '';
  $page_content .= l('返回列表','zibendaowei/jilu/fund') . '<br />'. '<br />';  
  drupal_set_title('管理该项资本到位记录');
	 
  $render_array = array(
	   '#markup' => $page_content,
	 );
	 
	 //该页面的正文为一个表单，注意对于表单，这里需要使用drupal_render呈现一下。
  $form = drupal_get_form('zibendaowei_jilu_edit_form',$perid);
  $render_array['#markup'] .= drupal_render($form);
	 
	 //Drupal7的页面回调，返回的应该是一个数组
  return $render_array;
}

function zibendaowei_jilu_edit_form($form, &$form_state, $perid){
  $query = "SELECT round_num,amount,timestamp,remark FROM " .
           "{daoweijilu} where id = ?";
  $queryResult = db_query($query, array($perid));
  foreach ($queryResult as $links ) {
  	$datetime = getdate($links->timestamp);
    $round_num = $links->round_num;
	$amount = $links->amount;
    $remark = $links->remark;
  }
  // More coming....
  if ($queryResult == '') {
    $form = NULL;
  }
  else{
   $form['bid'] = array('#type' => 'hidden', '#value' => $perid);
   $form['round_num'] = array(
	  '#title' => t('轮次'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['zibendaowei_jilu_edit_form']['round_num'])?$_SESSION['zibendaowei_jilu_edit_form']['round_num']:$round_num,
	 );
	 
	 $form['amount'] = array(
	  '#title' => t('出资金额（单位：万）'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['zibendaowei_jilu_edit_form']['amount'])?$_SESSION['zibendaowei_jilu_edit_form']['amount']:$amount,
	 );
	 
      $form['timestamp'] = array(
	     '#type' => 'date', // types 'date_popup', 'date_text' and 'date_timezone' are also supported. See .inc file.
	     '#title' => t('出资时间'),
	     '#default_value' => isset($_SESSION['zibendaowei_jilu_edit_form']['timestamp'])?$_SESSION['zibendaowei_jilu_edit_form']['timestamp']:
	     	array('year' =>  $datetime['year'], 'month' =>  $datetime['mon'], 'day' => $datetime['mday']), 
	  );
  	 
	 $form['remark'] = array(
	  '#title' => t('备注'),
	  '#type' => 'textarea',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['zibendaowei_jilu_edit_form']['remark'])?$_SESSION['zibendaowei_jilu_edit_form']['remark']:$remark,
	 );
	
	  $form['submit'] = array(
	    '#type' => 'submit',
	    '#value' => t('提交修改'),
	  );
	  
	 //表单元素“提交”按钮
	  $form['deleate'] = array(
	    '#type' => 'submit',
	    '#value' => t('删除该记录'),
	    '#submit' => array('zibendaowei_jilu_edit_form_deleate'),
	  );
  	
  }
  

  return $form;
}

function zibendaowei_jilu_edit_form_validate($form, &$form_state){
	  if (drupal_strlen($form_state['values']['amount']) > 10) {
	    form_set_error('amount', '要求精度小于10 个字符');
	  } 
	  if (!($form_state['values']['amount']>0)) {
	    form_set_error('amount', '请输入正数');
	  } 
	  if (!($form_state['values']['round_num']>0)) {
	    form_set_error('round_num', '请输入正数');
	  } 
	 
}

function zibendaowei_jilu_edit_form_submit($form, &$form_state){
	  $values = NULL;
	  $values = $form_state['values'];
      $datetime = mktime(0, 0, 0,$values['timestamp']['month'], $values['timestamp']['day'], $values['timestamp']['year']);
	  db_update('daoweijilu')
  		->fields(array(
   			 'round_num' => $values['round_num'],
   			 'amount' => $values['amount'],
   			 'timestamp' =>  $datetime,
   			 'remark' => $values['remark'],
  			))
  		->condition('id', $values['bid'])
  		->execute();
			$query = "SELECT fund_id FROM " .
		           "{daoweijilu} where id = ?";
		  $queryResult = db_query($query, array($values['bid']));
		  $fund_id = 0;
		  foreach ($queryResult as $links ) {
		  	$fund_id = $links->fund_id;
		  }
		$contributed_capital = 0;
		 $query = "SELECT amount FROM {daoweijilu} WHERE fund_id = ?";
			  $queryResult = db_query($query,array($fund_id));
			  foreach($queryResult as $fund){
				  $contributed_capital += $fund->amount;
			  }
		  	  db_update('fund_basic_information')
		  		->fields(array(
		   			 'contributed_capital' => $contributed_capital,
		  			))
		  		->condition('id', $fund_id)
		  		->execute();
	 $form_state['redirect'] = 'zibendaowei/jilu/ren';
}

function zibendaowei_jilu_edit_form_deleate($form, &$form_state){
	 $values = NULL;
	 $_SESSION['zibendaowei_jilu_edit_form'] = $form_state['values'];
	 $values = $_SESSION['zibendaowei_jilu_edit_form'] ;
	 //表单重定向到确认页面
	 $form_state['redirect'] = 'zibendaowei/jilu/deleate/'.$values['bid'];
}

function zibendaowei_jilu_deleate_page($perid) {
  // content variable that will be returned for display
  $page_content = '删除后该资本到位记录将不可恢复！';
  
  drupal_set_title('删除该资本到位记录');
	 
	 $render_array = array(
	   '#markup' => $page_content,
	 );
	 
	 //该页面的正文为一个表单，注意对于表单，这里需要使用drupal_render呈现一下。
	 $form = drupal_get_form('zibendaowei_jilu_deleate_form');
	 $render_array['#markup'] .= drupal_render($form);
	 
	 //Drupal7的页面回调，返回的应该是一个数组
  return $render_array;

}

function zibendaowei_jilu_deleate_form($form, &$form_state){
 //表单元素“返回”按钮
  $form['back'] = array(
    '#type' => 'submit',
    '#value' => t('取消'),
    '#submit' => array('zibendaowei_jilu_deleate_form_back'),
  );
 //表单元素“提交”按钮
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('删除'),
  );
  
  return $form;
}

function zibendaowei_jilu_deleate_form_back($form, &$form_state){
	if(empty($_SESSION['zibendaowei_jilu_edit_form'])){
		  //drupal_goto('contact');
		  $form_state['redirect'] = 'zibendaowei/jilu/fundlist';
	  }else{
		  $values = $_SESSION['zibendaowei_jilu_edit_form'];
		  unset($_SESSION['zibendaowei_jilu_edit_form']);
		  $form_state['redirect'] = 'zibendaowei/jilu/list/'.$values['bid'];
	  }
}

function zibendaowei_jilu_deleate_form_submit($form, &$form_state){
  //简单的重定向到contactus页面
 if(empty($_SESSION['zibendaowei_jilu_edit_form'])){
		  //drupal_goto('contact');
		  $form_state['redirect'] = 'zibendaowei/jilu/list';
	  }else{
		  $values = $_SESSION['zibendaowei_jilu_edit_form'];
		  unset($_SESSION['zibendaowei_jilu_edit_form']);
		  db_delete('daoweijilu')
			->condition('id' ,$values['bid'])
			->execute();
		  $form_state['redirect'] = 'zibendaowei/jilu/list';;
	  }

}

//出资人设置基金选择入口
function zibendaowei_jilu_fundlist_page() {
 $html = '';
 $header = array(
 	  array('data' => '序号'), 
      array('data' => '基金名称'),
      array('data' => '所属地区'),
      array('data' => '注册资本（万元）'),
      array('data' => '注册时间'),
      array('data' => '当前实缴资本（万元）'),
      array('data' => '到位比例'),
      array('data' => '操作'),
      );
  $query = db_select('fund_basic_information', 'n')
      ->extend('PagerDefault') //Pager Extender
      ->limit(15)//10 results per page
      ->extend('TableSort')//Sorting Extender
      ->orderByHeader($header)//Field to sort on is picked from $header
      ->fields ('n', array (
      'id',
      'registered_name',
      'area',
      'registered_capital',
      'contributed_capital',
      'registration_date',
      ));
  $results = $query
      ->execute();

  $rows = array();
  $serial_num = 1;
  foreach ($results as $node) {
  	   $bili = 0;
	   if( $node->registered_capital > 0){
	   	 $bili = $node->contributed_capital/$node->registered_capital;
	   }
		  $rows[] = array(
	      'data' => array(
	      	$serial_num,
	        l($node->registered_name, 'fund_basic_information/view/'. $node->id),
	        $node->area,
	        $node->registered_capital,
	        format_date($node->registration_date, 'custom', 'Y-m-d'),
	        $node->contributed_capital,
	        $bili,
	        l('查看', 'zibendaowei/jilu/fundlist/'.$node->id),
	      )
	      );
		  $serial_num += 1;
  }
  $html .= theme('table', 
      array(
            'header' => $header,
            'rows'=>$rows,
            //'caption' => '反馈意见列表',//Optional Caption for the table
            'sticky' => TRUE,//Optional to indicate whether the table headers should be sticky
            'empty' => '没有基金信息',//Optional empty text for the table if resultset is empty
      )
      );
  $html .= theme('pager',
      array(
            'tags' => array()
      )
      );
  return ($html); 
}

function zibendaowei_jilu_select_page($select) {
 $html = '';
 $form = drupal_get_form('zibendaowei_jilu_select_form',$select);
 $html .= drupal_render($form);
 list($area, $canye) = split ('[;.-]', $select); 
 $header = array(
 	  array('data' => '序号'), 
      array('data' => '基金名称'),
      array('data' => '所属地区'),
      array('data' => '产业领域'),
      array('data' => '注册资本（万元）'),
      array('data' => '当前实缴资本（万元）'),
      array('data' => '到位比例'),
      array('data' => '操作'),
      );
  $query = db_select('fund_basic_information', 'n')
      ->extend('PagerDefault') //Pager Extender
      ->extend('TableSort')//Sorting Extender
      ->orderByHeader($header)//Field to sort on is picked from $header
      ->fields ('n', array (
      'id',
      'registered_name',
      'area',
      'registered_capital',
      'contributed_capital',
      'investment_field',
      ));
  $results = $query
      ->execute();

  $rows = array();
  $serial_num = 0;
  $registered_capital = 0;
  $contributed_capital = 0;
  foreach ($results as $node) {
  	   if($area!="" && $node->area != ""){
  	   		if(!stristr($node->area,$area))
				break;
  	   }
	   if($canye!="" && $node->investment_field != ""){
  	   		if(!stristr($node->investment_field,$canye))
				break;
  	   }
  	   $bili = 0;
	   if( $node->registered_capital > 0){
	   	 $bili = $node->contributed_capital/$node->registered_capital;
	   }
	   $serial_num += 1;
	   $registered_capital += $node->registered_capital;
	   $contributed_capital += $node->contributed_capital;
		  $rows[] = array(
	      'data' => array(
	      	$serial_num,
	        l($node->registered_name, 'fund_basic_information/view/'. $node->id),
	        $node->area,
	        $node->investment_field,
	        $node->registered_capital,
	        $node->contributed_capital,
	        $bili,
	        l('查看', 'zibendaowei/jilu/fundlist/'.$node->id),
	      )
	      );
  }

  $bili = 0;
  if( $registered_capital > 0){
	   $bili = $contributed_capital/$registered_capital;
  }
  $html .= "<br><table><tr><th>基金个数</th> <td>".$serial_num."</td> <th>注册资本（万元）</th> <td>".$registered_capital."</td> 
  	<th>资本到位总额(万元)</th><td>".$contributed_capital."</td> <th>到位比例</th> <td>".$bili."</td> </tr></table><br>";
  $html .= theme('table', 
      array(
            'header' => $header,
            'rows'=>$rows,
            //'caption' => '反馈意见列表',//Optional Caption for the table
            'sticky' => TRUE,//Optional to indicate whether the table headers should be sticky
            'empty' => '没有基金信息',//Optional empty text for the table if resultset is empty
      )
      );
  $html .= theme('pager',
      array(
            'tags' => array()
      )
      );
	  
  return ($html); 
}

function zibendaowei_jilu_select_form($form, &$form_state,$select){
 //表单元素“返回”按钮
  list($area, $canye) = split ('[;.-]', $select);  
   $form['area'] = array(
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  "#prefix" => "<table border=\"1\" width=\"60%\" ><tr><th>所属地区</th><td>",
	  "#suffix" => "</td></tr>",
	  "#default_value" => $area,
	   );
  $form['canye'] = array(
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  "#prefix" => "<tr><th>投资产业领域</th><td>",
	  "#suffix" => "</td></tr></table>",
	  "#default_value" => $canye,
	   );   
 //表单元素“提交”按钮
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('搜索'),
  );
  
  return $form;
}

function zibendaowei_jilu_select_form_submit($form, &$form_state){
	  $values = NULL;
	  $values = $form_state['values'];
	  $form_state['redirect'] = 'zibendaowei/jilu/select/'.$values['area'].";".$values['canye'];
}
function zibendaowei_jilu_fund_page() {
 	$html = '';
 	global $user;
	$query = "SELECT id,registered_name,area,registered_capital,contributed_capital,agree_contribute_time_percentage FROM {fund_basic_information} WHERE user_id = ?";
	$query_result = db_query($query,array($user->uid));
	$fund_id = "";
	$registered_capital = 0;
    foreach ($query_result as $result_values ) {
		$bili = 0;
		$registered_capital = $result_values->registered_capital;
		if($result_values->contributed_capital>0 && $result_values->registered_capital>0){
			$bili = $result_values->contributed_capital/$result_values->registered_capital;
		}
		$fund_id = $result_values->id;
		$html .= "<br><table width=\"100%\"><tr><td width=\"15%\">注册资本（万元）</td><td width=\"15%\">".$result_values->registered_capital."</td><td width=\"20%\">当前实缴资本（万元）</td>
		<td width=\"15%\">".$result_values->contributed_capital."</td><td width=\"15%\">到位比例</td><td width=\"15%\">".$bili."</td></tr>";
		$html .= "<tr><td>基金章程/合伙人协议对出资时间和出资比例的约定：</td><td colspan=5>".$result_values->agree_contribute_time_percentage."</td></tr></table><br>";
	}
	
	$header = array(
      array('data' => '轮次'),
      array('data' => '序号'),
      array('data' => '出资人'),
      array('data' => '出资人属性'),
      array('data' => '承诺出资金额（万元）'),
      array('data' => '出资时间'),
      array('data' => '出资金额（万元）'),
      array('data' => '到位比例'),
      array('data' => '操作'),
      );
  
  $rows = array();
  $current_round = 1;
  while(TRUE){
  	$serial_num = 1;
  	$query = db_select('daoweijilu', 'n')
	      ->extend('PagerDefault') //Pager Extender
	      ->extend('TableSort')//Sorting Extender
	      ->orderByHeader($header)//Field to sort on is picked from $header
	      ->fields ('n', array (
	      'id',
	      'amount',
	      'chuziren_id',
	      'timestamp',
	      'chuziren_type',
	      ))
		  ->condition('round_num',$current_round,'=')
		  ->condition('fund_id',$fund_id,'=');
	 $results = $query
	      ->execute();
     $heji = 0;
     foreach ($results as $node) {
		  $type = "个人";
		  $promise_amount = 0;
		  $name = "";
		  if($node->chuziren_type == 1){
		  	$query_chuziren = "SELECT company_name,company_type, promise_amount FROM {chuziren_info} WHERE id = ?";
			$query_result = db_query($query_chuziren,array($node->chuziren_id));		
		    foreach ($query_result as $result_values ) {
		    	$type = $result_values->company_type;
				$promise_amount = $result_values->promise_amount;
				$name = $result_values->company_name;
		    }
		  }
		  else{
		  	$query_chuziren = "SELECT geren_name,promise_amount FROM {chuziren_geren_info} WHERE id = ?";
			$query_result = db_query($query_chuziren,array($node->chuziren_id));		
		    foreach ($query_result as $result_values ) {
				$promise_amount = $result_values->promise_amount;
				$name = $result_values->geren_name;
		    }
		  }
		  $bili = 0;
		  if($node->amount>0 && $promise_amount>0){
			$bili = $node->amount/$promise_amount;
		  }
		  $rows[] = array(
	      'data' => array(
	        $current_round,
	        $serial_num,
	        $name,
	        $type,
	        $promise_amount,
	        format_date($node->timestamp, 'custom', 'Y-m-d'),
	        $node->amount,
	        $bili,
	        l('编辑', 'zibendaowei/jilu/edit/'.$node->id)
	      )
	      );
		  
		  $serial_num += 1;
		  $heji += $node->amount;
  	 }
	  if($serial_num==1)
	 	break;
	 $bili = 0;
	 if($registered_capital > 0)
	 	$bili = $heji/$registered_capital;
     $rows[] = array(
	      'data' => array(
	        $current_round.'轮合计',
	        '--',
	        '--',
	        '--',
	        $registered_capital,
	        '--',
	        $heji,
	        $bili,
	        "--"
	       )
	      );
	
	 $current_round += 1;
  }
  
  $html .= theme('table', 
      array(
            'header' => $header,
            'rows'=>$rows,
            //'caption' => '反馈意见列表',//Optional Caption for the table
            'sticky' => TRUE,//Optional to indicate whether the table headers should be sticky
            'empty' => '没有信息',//Optional empty text for the table if resultset is empty
      )
      );
  $html .= theme('pager',
      array(
            'tags' => array()
      )
      );
  return ($html); 
 
}

//出资人选择入口
function zibendaowei_jilu_ren_page() {
 $html = '';
 global $user;
	$query = "SELECT id,registered_name,area,registered_capital,contributed_capital,agree_contribute_time_percentage FROM {fund_basic_information} WHERE user_id = ?";
	$query_result = db_query($query,array($user->uid));
	$fund_id = "";
	$registered_capital = 0;
    foreach ($query_result as $result_values ) {
		$bili = 0;
		$registered_capital = $result_values->registered_capital;
		if($result_values->contributed_capital>0 && $result_values->registered_capital>0){
			$bili = $result_values->contributed_capital/$result_values->registered_capital;
		}
		$fund_id = $result_values->id;
		$html .= "<br><table width=\"100%\"><tr><td width=\"15%\">注册资本（万元）</td><td width=\"15%\">".$result_values->registered_capital."</td><td width=\"20%\">当前实缴资本（万元）</td>
		<td width=\"15%\">".$result_values->contributed_capital."</td><td width=\"15%\">到位比例</td><td width=\"15%\">".$bili."</td></tr>";
		$html .= "<tr><td>基金章程/合伙人协议对出资时间和出资比例的约定：</td><td colspan=5>".$result_values->agree_contribute_time_percentage."</td></tr></table><br>";
	}
  //$html .= '出资人（公司）列表<br>';
  $header = array(
      array('data' => '序号'),
      array('data' => '出资人'),
      array('data' => '出资人属性'),
      array('data' => '承诺出资金额/认购总股本(万元)'),
      array('data' => '占股比例'),
      array('data' => '资本到位管理'),
      );
  $query = db_select('chuziren_info', 'n')
      ->extend('PagerDefault') //Pager Extender
      ->limit(20)//20 results per page
      ->extend('TableSort')//Sorting Extender
      ->orderByHeader($header)//Field to sort on is picked from $header
      ->fields ('n', array (
      'id',
      'company_name',
      'company_type',
      'promise_amount',
      'promise_bili',
      ))
	  ->condition('fund_id',$fund_id,'=');
  $results = $query
      ->execute();

  $rows = array();
  $_serial_num = 1;
  foreach ($results as $node) {
      $rows[] = array(
      'data' => array(
        $_serial_num,
        $node->company_name,
        $node->company_type,
        $node->promise_amount,
        $node->promise_bili,
         l('管理', 'zibendaowei/jilu/renlist/'. $node->id),
      )
      );
	  $_serial_num +=1;
  }
  $query = db_select('chuziren_geren_info', 'n')
      ->extend('PagerDefault') //Pager Extender
      ->limit(20)//20 results per page
      ->extend('TableSort')//Sorting Extender
      ->orderByHeader($header)//Field to sort on is picked from $header
      ->fields ('n', array (
      'id',
      'geren_name',
      'promise_amount',
      'promise_bili',
      ))
	  ->condition('fund_id',$fund_id,'=');
  $results = $query
      ->execute();

 // $rows = array();
  //$_serial_num = 1;
  foreach ($results as $node) {
      $rows[] = array(
      'data' => array(
        $_serial_num,
        $node->geren_name,
        '个人',
        $node->promise_amount,
        $node->promise_bili,
         l('管理', 'zibendaowei/jilu/geren/'. $node->id),
      )
      );
	  $_serial_num +=1;
  }
  $html .= theme('table', 
      array(
            'header' => $header,
            'rows'=>$rows,
            //'caption' => '反馈意见列表',//Optional Caption for the table
            'sticky' => TRUE,//Optional to indicate whether the table headers should be sticky
            'empty' => '没有出资人信息',//Optional empty text for the table if resultset is empty
      )
      );
  $html .= '</div>';
  $html .= theme('pager',
      array(
            'tags' => array()
      )
      );
  return ($html);   
   $html .= '<br>出资人（个人）列表<br>';
  $header = array(
      array('data' => '序号'),
      array('data' => '出资人'),
      array('data' => '出资人属性'),
      array('data' => '承诺出资金额/认购总股本(万元)'),
      array('data' => '占股比例'),
      array('data' => '资本到位管理'),
      );
  $query = db_select('chuziren_geren_info', 'n')
      ->extend('PagerDefault') //Pager Extender
      ->limit(20)//20 results per page
      ->extend('TableSort')//Sorting Extender
      ->orderByHeader($header)//Field to sort on is picked from $header
      ->fields ('n', array (
      'id',
      'geren_name',
      'promise_amount',
      'promise_bili',
      ))
	  ->condition('fund_id',$fund_id,'=');
  $results = $query
      ->execute();

  $rows = array();
  $_serial_num = 1;
  foreach ($results as $node) {
      $rows[] = array(
      'data' => array(
        $_serial_num,
        $node->geren_name,
        '个人',
        $node->promise_amount,
        $node->promise_bili,
         l('管理', 'zibendaowei/jilu/geren/'. $node->id),
      )
      );
	  $_serial_num +=1;
  }
  $html .= theme('table', 
      array(
            'header' => $header,
            'rows'=>$rows,
            //'caption' => '反馈意见列表',//Optional Caption for the table
            'sticky' => TRUE,//Optional to indicate whether the table headers should be sticky
            'empty' => '没有出资人信息',//Optional empty text for the table if resultset is empty
      )
      );
  $html .= '</div>';
  $html .= theme('pager',
      array(
            'tags' => array()
      )
      );
  
  return ($html); 
}

//传人基金id
function zibendaowei_jilu_fundlist_perpage($fund_id) {
  $html = ''; 	
  $html .= l('返回列表','zibendaowei/jilu/fundlist') . '<br>';
    
  $query = "SELECT registered_name,area,registered_capital,contributed_capital,agree_contribute_time_percentage FROM {fund_basic_information} WHERE id = ?";
	$query_result = db_query($query,array($fund_id));
	$registered_capital = 0;
    foreach ($query_result as $result_values ) {
		$bili = 0;
		$registered_capital = $result_values->registered_capital;
		if($result_values->contributed_capital>0 && $result_values->registered_capital>0){
			$bili = $result_values->contributed_capital/$result_values->registered_capital;
		}
		$html .= "<br><table width=\"100%\"><tr><td width=\"15%\">注册资本（万元）</td><td width=\"15%\">".$result_values->registered_capital."</td><td width=\"20%\">当前实缴资本（万元）</td>
		<td width=\"15%\">".$result_values->contributed_capital."</td><td width=\"15%\">到位比例</td><td width=\"15%\">".$bili."</td></tr>";
		$html .= "<tr><td>基金章程/合伙人协议对出资时间和出资比例的约定：</td><td colspan=5>".$result_values->agree_contribute_time_percentage."</td></tr></table><br>";
	}
	
	$header = array(
      array('data' => '轮次'),
      array('data' => '序号'),
      array('data' => '出资人'),
      array('data' => '出资人属性'),
      array('data' => '承诺出资金额（万元）'),
      array('data' => '出资时间'),
      array('data' => '出资金额（万元）'),
      array('data' => '到位比例'),
      array('data' => '操作'),
      );
  
  $rows = array();
  $current_round = 1;
  while(TRUE){
  	$serial_num = 1;
  	$query = db_select('daoweijilu', 'n')
	      ->extend('PagerDefault') //Pager Extender
	      ->extend('TableSort')//Sorting Extender
	      ->orderByHeader($header)//Field to sort on is picked from $header
	      ->fields ('n', array (
	      'id',
	      'amount',
	      'chuziren_id',
	      'timestamp',
	      'chuziren_type'
	      ))
		  ->condition('round_num',$current_round,'=')
		  ->condition('fund_id',$fund_id,'=');
	 $results = $query
	      ->execute();
     $heji = 0;
     foreach ($results as $node) {
		  $type = "个人";
		  $promise_amount = 0;
		  $name = "";
		  if($node->chuziren_type == 1){
		  	$query_chuziren = "SELECT company_name,company_type, promise_amount FROM {chuziren_info} WHERE id = ?";
			$query_result = db_query($query_chuziren,array($node->chuziren_id));		
		    foreach ($query_result as $result_values ) {
		    	$type = $result_values->company_type;
				$promise_amount = $result_values->promise_amount;
				$name = $result_values->company_name;
		    }
		  }
		  else{
		  	$query_chuziren = "SELECT geren_name,promise_amount FROM {chuziren_geren_info} WHERE id = ?";
			$query_result = db_query($query_chuziren,array($node->chuziren_id));		
		    foreach ($query_result as $result_values ) {
				$promise_amount = $result_values->promise_amount;
				$name = $result_values->geren_name;
		    }
		  }
		  $bili = 0;
		  if($node->amount>0 && $promise_amount>0){
			$bili = $node->amount/$promise_amount;
		  }
		  $rows[] = array(
	      'data' => array(
	        $current_round,
	        $serial_num,
	        $name,
	        $type,
	        $promise_amount,
	        format_date($node->timestamp, 'custom', 'Y-m-d'),
	        $node->amount,
	        $bili,
	        l('浏览', 'zibendaowei/jilu/view/'.$node->id)
	      )
	      );
		  
		  $serial_num += 1;
		  $heji += $node->amount;
  	 }
	 $bili = 0;
	 if($serial_num==1)
	 	break;
	 if($registered_capital > 0)
	 	$bili = $heji/$registered_capital;
     $rows[] = array(
	      'data' => array(
	        $current_round.'轮合计',
	        '--',
	        '--',
	        '--',
	        $registered_capital,
	        '--',
	        $heji,
	        $bili,
	        "--"
	       )
	      );
	 
	 $current_round += 1;
  }
  
  $html .= theme('table', 
      array(
            'header' => $header,
            'rows'=>$rows,
            //'caption' => '反馈意见列表',//Optional Caption for the table
            'sticky' => TRUE,//Optional to indicate whether the table headers should be sticky
            'empty' => '没有信息',//Optional empty text for the table if resultset is empty
      )
      );
  $html .= theme('pager',
      array(
            'tags' => array()
      )
      );
  return ($html); 
}

//传人出资人id
function zibendaowei_jilu_renlist_page($chuziren_id) {

  $query = "SELECT promise_amount FROM " .
           "{chuziren_info} where id = ?";
  $queryResult = db_query($query, array($chuziren_id));
  $promise_amount = '';
  foreach($queryResult as $fund){
	  $promise_amount = $fund->promise_amount;
  }
  $html = l('返回列表','zibendaowei/jilu/ren') . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  
  $html .= l('添加资本到位记录','zibendaowei/jilu/create/'.$chuziren_id) . '<br />';
  
  $header = array(
      array('data' => '轮次'),
      array('data' => '序号'),
      array('data' => '出资人'),
      array('data' => '出资人属性'),
      array('data' => '承诺出资金额（万元）'),
      array('data' => '出资时间'),
      array('data' => '出资金额（万元）'),
      array('data' => '到位比例'),
      array('data' => '操作'),
      );
  
  $rows = array();
  $current_round = 1;
  while(TRUE){
  	$serial_num = 1;
  	$query = db_select('daoweijilu', 'n')
	      ->extend('PagerDefault') //Pager Extender
	      ->extend('TableSort')//Sorting Extender
	      ->orderByHeader($header)//Field to sort on is picked from $header
	      ->fields ('n', array (
	      'id',
	      'amount',
	      'chuziren_id',
	      'timestamp'
	      ))
		  ->condition('round_num',$current_round,'=')
		  ->condition('chuziren_id',$chuziren_id,'=')
		  ->condition('chuziren_type',1,'=');
		  
	 $results = $query
	      ->execute();
     $heji = 0;
     foreach ($results as $node) {
		  $type = "个人";
		  $promise_amount = 0;
		  $name = "";

		  	$query_chuziren = "SELECT company_name,company_type, promise_amount FROM {chuziren_info} WHERE id = ?";
			$query_result = db_query($query_chuziren,array($node->chuziren_id));		
		    foreach ($query_result as $result_values ) {
		    	$type = $result_values->company_type;
				$promise_amount = $result_values->promise_amount;
				$name = $result_values->company_name;
		    }
		  
		  $bili = 0;
		  if($node->amount>0 && $promise_amount>0){
			$bili = $node->amount/$promise_amount;
		  }
		  $rows[] = array(
	      'data' => array(
	        $current_round,
	        $serial_num,
	        $name,
	        $type,
	        $promise_amount,
	        format_date($node->timestamp, 'custom', 'Y-m-d'),
	        $node->amount,
	        $bili,
	        l('编辑', 'zibendaowei/jilu/edit/'.$node->id)
	      )
	      );
		  
		  $serial_num += 1;
		  $heji += $node->amount;
  	 }
	 
	 if($serial_num==1)
	 	break;
	 $bili = 0;
	 if($promise_amount > 0)
	 	$bili = $heji/$promise_amount;
     $rows[] = array(
	      'data' => array(
	        $current_round.'轮合计',
	        '--',
	        '--',
	        '--',
	        $promise_amount,
	        '--',
	        $heji,
	        $bili,
	        "--"
	       )
	      );
	 $current_round += 1;
  }
  
  $html .= theme('table', 
      array(
            'header' => $header,
            'rows'=>$rows,
            //'caption' => '反馈意见列表',//Optional Caption for the table
            'sticky' => TRUE,//Optional to indicate whether the table headers should be sticky
            'empty' => '没有信息',//Optional empty text for the table if resultset is empty
      )
      );
  $html .= theme('pager',
      array(
            'tags' => array()
      )
      );

  
  return ($html); 
}


function zibendaowei_jilu_geren_page($chuziren_id) {

  $query = "SELECT promise_amount FROM " .
           "{chuziren_geren_info} where id = ?";
  $queryResult = db_query($query, array($chuziren_id));
  $promise_amount = '';
  foreach($queryResult as $fund){
	  $promise_amount = $fund->promise_amount;
  }
  $html = l('返回列表','zibendaowei/jilu/ren') . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  
  $html .= l('添加资本到位记录','zibendaowei/jilu_geren/create/'.$chuziren_id) . '<br />';
  
  $header = array(
      array('data' => '轮次'),
      array('data' => '序号'),
      array('data' => '出资人'),
      array('data' => '出资人属性'),
      array('data' => '承诺出资金额（万元）'),
      array('data' => '出资时间'),
      array('data' => '出资金额（万元）'),
      array('data' => '到位比例'),
      array('data' => '操作'),
      );
  
  $rows = array();
  $current_round = 1;
  while(TRUE){
  	$serial_num = 1;
  	$query = db_select('daoweijilu', 'n')
	      ->extend('PagerDefault') //Pager Extender
	      ->extend('TableSort')//Sorting Extender
	      ->orderByHeader($header)//Field to sort on is picked from $header
	      ->fields ('n', array (
	      'id',
	      'amount',
	      'chuziren_id',
	      'timestamp',
	      ))
		  ->condition('round_num',$current_round,'=')
		  ->condition('chuziren_id',$chuziren_id,'=')
		  ->condition('chuziren_type',2,'=');
	 $results = $query
	      ->execute();
     $heji = 0;
     foreach ($results as $node) {
		  $type = "个人";
		  $promise_amount = 0;
		  $name = "";
		  
		  	$query_chuziren = "SELECT geren_name,promise_amount FROM {chuziren_geren_info} WHERE id = ?";
			$query_result = db_query($query_chuziren,array($node->chuziren_id));		
		    foreach ($query_result as $result_values ) {
				$promise_amount = $result_values->promise_amount;
				$name = $result_values->geren_name;
		    }
		  
		  $bili = 0;
		  if($node->amount>0 && $promise_amount>0){
			$bili = $node->amount/$promise_amount;
		  }
		  $rows[] = array(
	      'data' => array(
	        $current_round,
	        $serial_num,
	        $name,
	        $type,
	        $promise_amount,
	        format_date($node->timestamp, 'custom', 'Y-m-d'),
	        $node->amount,
	        $bili,
	        l('编辑', 'zibendaowei/jilu/edit/'.$node->id)
	      )
	      );
		  
		  $serial_num += 1;
		  $heji += $node->amount;
  	 }
	if($serial_num==1)
	 	break;
	 $bili = 0;
	 if($promise_amount > 0)
	 	$bili = $heji/$promise_amount;
     $rows[] = array(
	      'data' => array(
	        $current_round.'轮合计',
	        '--',
	        '--',
	        '--',
	        $promise_amount,
	        '--',
	        $heji,
	        $bili,
	        "--"
	       )
	      );
	 
	 $current_round += 1;
  }
  
  $html .= theme('table', 
      array(
            'header' => $header,
            'rows'=>$rows,
            //'caption' => '反馈意见列表',//Optional Caption for the table
            'sticky' => TRUE,//Optional to indicate whether the table headers should be sticky
            'empty' => '没有信息',//Optional empty text for the table if resultset is empty
      )
      );
  $html .= theme('pager',
      array(
            'tags' => array()
      )
      );

  
  return ($html); 
}

/////////
//出资人（公司）管理
/////////
//传人基金id（基金基本信息表）
function chuziren_create_confirm(){
	$html = "<br>";
	
	$html .= "请选择出资人类型：&nbsp;&nbsp;".l('公司','chuziren/create') ."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	$html .= l('个人','chuziren_geren/create');
	
	return $html;
}

function chuziren_create(){
	  //我们为这个页面设置标题
	drupal_set_title('新增出资人信息');
	global $user;
	$query = "SELECT id,registered_name FROM " .
           "{fund_basic_information} where user_id = ?";
    $queryResult = db_query($query, array($user->uid));
	$fund_id = 0;
    foreach ($queryResult as $result) {
    	$fund_id = $result->id;
		$page_content = l('返回列表','chuziren/fund') . '<br />'. '<br />';
    	 $page_content .= '当前基金：' . '&nbsp;&nbsp;'. $result->registered_name.'<br><br>';
	}
	if ($fund_id==0){
		drupal_goto('chuziren/fund');
	}
	 
	 $render_array = array(
	   '#markup' => $page_content, 
	 );
	 
	 $form = drupal_get_form('chuziren_form',$fund_id);
	 $render_array['#markup'] .= drupal_render($form);
	 
	 return $render_array;
}

function chuziren_form($form, &$form_state, $fund_id){
	 $form['bid'] = array('#type' => 'hidden', '#value' => $fund_id);
	 
	 $form['tips'] = array(
	  '#prefix' =>'<div id="tips">',
	  '#markup' => t('<span class="form-required">*</span> 号为必填项。'),
	  '#suffix' =>'</div>',
	 );
	 
	 $form['company_name'] = array(
	  '#title' => t('出资人名称'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['company_name'])?$_SESSION['chuziren_form']['company_name']:"",
	 );
	 $form['address'] = array(
	  '#title' => t('办公地址'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['address'])?$_SESSION['chuziren_form']['address']:"",
	 );
	 $form['fadingdaibiaoren'] = array(
	  '#title' => t('法定代表人'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['fadingdaibiaoren'])?$_SESSION['chuziren_form']['fadingdaibiaoren']:"",
	 );
	  $form['zuce_money'] = array(
	  '#title' => t('注册资本（万元）'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['zuce_money'])?$_SESSION['chuziren_form']['zuce_money']:"",
	 );
	 $form['company_money'] = array(
	  '#title' => t('净资产（万元）'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['company_money'])?$_SESSION['chuziren_form']['company_money']:"",
	 );
	 $form['company_type'] = array(
	  '#title' => t('出资人属性(政府/私企/国企)'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['company_type'])?$_SESSION['chuziren_form']['company_type']:"",
	 ); 
	 $today = getdate();
     $form['timestamp'] = array(
	     '#type' => 'date', // types 'date_popup', 'date_text' and 'date_timezone' are also supported. See .inc file.
	     '#title' => t('成立时间'),
	     '#default_value' => array('year' =>  $today['year'], 'month' =>  $today['mon'], 'day' => $today['mday']), 
	  );
	  $form['promise_amount'] = array(
	  '#title' => t('承诺出资额（万元）'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['promise_amount'])?$_SESSION['chuziren_form']['promise_amount']:"",
	 );
	 $form['promise_bili'] = array(
	  '#title' => t('承诺出资比例'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['promise_bili'])?$_SESSION['chuziren_form']['promise_bili']:"",
	 );
	 $form['konggu'] = array(
	  '#title' => t('实际控制人或控股股东'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['konggu'])?$_SESSION['chuziren_form']['konggu']:"",
	 ); 
	 $form['lianxiren'] = array(
	  '#title' => t('联系人'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['lianxiren'])?$_SESSION['chuziren_form']['lianxiren']:"",
	 ); 
	  $form['lianxirenzhiwu'] = array(
	  '#title' => t('联系人职务'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['lianxirenzhiwu'])?$_SESSION['chuziren_form']['lianxirenzhiwu']:"",
	 ); 
	  $form['mobile'] = array(
	  '#title' => t('手机'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['mobile'])?$_SESSION['chuziren_form']['mobile']:"",
	 ); 
	  $form['phone'] = array(
	  '#title' => t('电话'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['phone'])?$_SESSION['chuziren_form']['phone']:"",
	 ); 
	  $form['chuanzhen'] = array(
	  '#title' => t('传真'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['chuanzhen'])?$_SESSION['chuziren_form']['chuanzhen']:"",
	 ); 
	  $form['lianximail'] = array(
	  '#title' => t('联系邮箱'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['lianximail'])?$_SESSION['chuziren_form']['lianximail']:"",
	 ); 
  	 $form['company_info'] = array(
	  '#title' => t('出资人简介'),
	  '#type' => 'textarea',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['company_info'])?$_SESSION['chuziren_form']['company_info']:"",
	 );
	 $form['remark'] = array(
	  '#title' => t('备注'),
	  '#type' => 'textarea',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['remark'])?$_SESSION['chuziren_form']['remark']:"",
	 );
	 $form['upload1'] = array(
		'#type' => 'managed_file',
		'#title' => '营业执照',
		'#required' => FALSE,
		'#upload_location' => 'public://my_uploads',
		'#upload_validators' => array(
	    'file_validate_extensions' => array('doc xls pdf docx xlsx zip tar.gz 7z'),
		'file_validate_size' => array(20*1024*1024)),
	);
	$form['upload2'] = array(
		'#type' => 'managed_file',
		'#title' => '税务登记证',
		'#required' => FALSE,
		'#upload_location' => 'public://my_uploads',
		'#upload_validators' => array(
	    'file_validate_extensions' => array('doc xls pdf docx xlsx zip tar.gz 7z'),
		'file_validate_size' => array(20*1024*1024)),
	);
	$form['upload3'] = array(
		'#type' => 'managed_file',
		'#title' => '组织机构代码证',
		'#required' => FALSE,
		'#upload_location' => 'public://my_uploads',
		'#upload_validators' => array(
	    'file_validate_extensions' => array('doc xls pdf docx xlsx zip tar.gz 7z'),
		'file_validate_size' => array(20*1024*1024)),
	);
	$form['upload4'] = array(
		'#type' => 'managed_file',
		'#title' => '法定代表人身份证',
		'#required' => FALSE,
		'#upload_location' => 'public://my_uploads',
		'#upload_validators' => array(
	    'file_validate_extensions' => array('doc xls pdf docx xlsx zip tar.gz 7z'),
		'file_validate_size' => array(20*1024*1024)),
	);
	
	  $form['submit'] = array(
	    '#type' => 'submit',
	    '#value' => t('确认'),
	  );
	  return $form;
}

function chuziren_form_validate($form, &$form_state){
	  if (drupal_strlen($form_state['values']['company_money']) > 10) {
	    form_set_error('company_money', '要求精度小于10 个字符');
	  } 
	  if (!($form_state['values']['company_money']>=0||$form_state['values']['company_money']<0)) {
	    form_set_error('company_money', '请输入数字');
	  }
	  if (drupal_strlen($form_state['values']['zuce_money']) > 10) {
	    form_set_error('zuce_money', '要求精度小于10 个字符');
	  } 
	  if (!($form_state['values']['zuce_money']>=0)) {
	    form_set_error('zuce_money', '请输入正数');
	  } 
	  if (drupal_strlen($form_state['values']['promise_amount']) > 10) {
	    form_set_error('promise_amount', '要求精度小于10 个字符');
	  } 
	  if (!($form_state['values']['promise_amount']>0)) {
	    form_set_error('promise_amount', '请输入正数');
	  } 
	  
}

function chuziren_form_submit($form, &$form_state){
	  //把表单的值存放在会话中去，由于这里涉及到了两个不同的表单之间传值。
	// $_SESSION['chuziren_form'] = $form_state['values'];
	 //表单重定向到确认页面
	 //$form_state['redirect'] = 'chuziren/confirm';
	  	 
	$values=$form_state['values'];	
    $datetime = mktime(0, 0, 0,$values['timestamp']['month'], $values['timestamp']['day'], $values['timestamp']['year']);
	$last_id = db_insert('chuziren_info')
  		->fields(array(
  		     'fund_id' => $values['bid'],
   			 'company_name' => $values['company_name'],
   			 'address' => $values['address'],
   			 'fadingdaibiaoren' => $values['fadingdaibiaoren'],
   			 'company_money' => $values['company_money'],
   			 'zuce_money' => $values['zuce_money'],
   			 'company_type' => $values['company_type'],
   			 'timestamp' =>  $datetime,
   			 'promise_amount' => $values['promise_amount'],
   			 'promise_bili' => $values['promise_bili'],
   			 'konggu' => $values['konggu'],
			 'lianxiren' => $values['lianxiren'],
			 'lianxirenzhiwu' => $values['lianxirenzhiwu'],
			 'mobile' => $values['mobile'],
			 'phone' => $values['phone'],
			 'chuanzhen' => $values['chuanzhen'],
			 'lianximail' => $values['lianximail'],
   			 'company_info' => $values['company_info'],
   			 'remark' => $values['remark'],
  			))->execute();
	  if ($last_id!=NULL) {
	  	    $fid = $form_state['values']['upload1']; 
			$file = file_load($fid);  
			global $user; 
			if ($file != null) {
				$saveurl = file_uri_target($file->uri);
				$fid = $file->fid;   
				//$extension_errors=file_validate_extensions($file, "jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp docx");   
			    $extension_errors=file_validate_extensions($file, "doc xls pdf docx xlsx zip tar.gz 7z");   
				if (!$extension_errors) {  
					$file->status = FILE_STATUS_PERMANENT;   
					file_save($file);			
						db_update('chuziren_info')
					  		->fields(array(
					   			 'url1' => $saveurl,					   			
					   			 'file_managed_id1' => $fid,
					  		     ))->execute();
				} 
				else {
				form_set_error('upload',$extension_errors[0]); 
				}
			}

			$fid = $form_state['values']['upload2']; 
			$file = file_load($fid);  
			
			if ($file != null) {
				$saveurl = file_uri_target($file->uri);
				$fid = $file->fid;   
				//$extension_errors=file_validate_extensions($file, "jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp docx");   
			    $extension_errors=file_validate_extensions($file, "doc xls pdf docx xlsx zip tar.gz 7z");   
				if (!$extension_errors) {  
					$file->status = FILE_STATUS_PERMANENT;   
					file_save($file);			
						db_update('chuziren_info')
					  		->fields(array(
					   			 'url2' => $saveurl,					   			
					   			 'file_managed_id2' => $fid,
					  		     ))->execute();
				} 
				else {
				form_set_error('upload',$extension_errors[0]); 
				}
			}
			
			$fid = $form_state['values']['upload3']; 
			$file = file_load($fid);  
			if ($file != null) {
				$saveurl = file_uri_target($file->uri);
				$fid = $file->fid;   
				//$extension_errors=file_validate_extensions($file, "jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp docx");   
			    $extension_errors=file_validate_extensions($file, "doc xls pdf docx xlsx zip tar.gz 7z");   
				if (!$extension_errors) {  
					$file->status = FILE_STATUS_PERMANENT;   
					file_save($file);			
						db_update('chuziren_info')
					  		->fields(array(
					   			 'url3' => $saveurl,					   			
					   			 'file_managed_id3' => $fid,
					  		     ))->execute();
				} 
				else {
				form_set_error('upload',$extension_errors[0]); 
				}
			}
			
			$fid = $form_state['values']['upload4']; 
			$file = file_load($fid);  
			if ($file != null) {
				$saveurl = file_uri_target($file->uri);
				$fid = $file->fid;   
				//$extension_errors=file_validate_extensions($file, "jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp docx");   
			    $extension_errors=file_validate_extensions($file, "doc xls pdf docx xlsx zip tar.gz 7z");   
				if (!$extension_errors) {  
					$file->status = FILE_STATUS_PERMANENT;   
					file_save($file);			
						db_update('chuziren_info')
					  		->fields(array(
					   			 'url4' => $saveurl,					   			
					   			 'file_managed_id4' => $fid,
					  		     ))->execute();
				} 
				else {
				form_set_error('upload',$extension_errors[0]); 
				}
			}
			 $form_state['redirect'] = 'chuziren/fund';
	  } else {	    
	    // 数据写入失败了
	      drupal_set_message('抱歉，遇到问题，提交失败了', 'error');
	    
	  }	
}
 
//传人基金id
function chuziren_fundlist_perpage($fund_id) {
  $html = l('返回基金列表','chuziren/fundlist') . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';  
 
  //$html .= '<br>出资人（公司）列表<br>';
  $query = "SELECT id, registered_name FROM " .
           "{fund_basic_information} where id = ?";
  $queryResult = db_query($query, array($fund_id));
  foreach($queryResult as $result){
  	$html .= '当前基金：' . '&nbsp;&nbsp;'. $result->registered_name.'<br><br>';
  }
  $html .= '<div id="printable_div">';
  $round_num = 1;
  $header = array(
      array('data' => '序号'),
      array('data' => '出资人', 'field' => 'company_name'),
      array('data' => '出资人属性', 'field' => 'company_type'),
      array('data' => '承诺出资金额/认购总股本(万元)', 'field' => 'promise_amount'),
      array('data' => '占股比例', 'field' => 'percentage'),
      array('data' => '详情', 'field' => 'more'),
      );
  $query = db_select('chuziren_info', 'n')
      ->extend('PagerDefault') //Pager Extender
      ->limit(20)//20 results per page
      ->extend('TableSort')//Sorting Extender
      ->orderByHeader($header)//Field to sort on is picked from $header
      ->fields ('n', array (
      'id',
      'company_name',
      'company_type',
      'promise_amount',
      'promise_bili',
      ))
	  ->condition('fund_id',$fund_id,'=');
  $results = $query
      ->execute();

  $rows = array();
  $_serial_num = 1;
  foreach ($results as $node) {
  	
      $rows[] = array(
      'data' => array(
        $_serial_num,
        $node->company_name,
        $node->company_type,
        $node->promise_amount,
        $node->promise_bili,
         l('查看详情', 'chuziren/list/'. $node->id),
      )
      );
	  $_serial_num +=1;
  }
    $query = db_select('chuziren_geren_info', 'n')
      ->extend('PagerDefault') //Pager Extender
      ->limit(20)//20 results per page
      ->extend('TableSort')//Sorting Extender
      ->orderByHeader($header)//Field to sort on is picked from $header
      ->fields ('n', array (
      'id',
      'geren_name',
      'promise_amount',
      'promise_bili',
      ))
	  ->condition('fund_id',$fund_id,'=');
  $results = $query
      ->execute();

  //$rows = array();
  //$_serial_num = 1;
  foreach ($results as $node) {
      $rows[] = array(
      'data' => array(
        $_serial_num,
        $node->geren_name,
        '个人',
        $node->promise_amount,
        $node->promise_bili,
         l('查看详情', 'chuziren_geren/list/'. $node->id),
      )
      );
	  $_serial_num +=1;
  }
  $html .= theme('table', 
      array(
            'header' => $header,
            'rows'=>$rows,
            //'caption' => '反馈意见列表',//Optional Caption for the table
            'sticky' => TRUE,//Optional to indicate whether the table headers should be sticky
            'empty' => '没有出资人信息',//Optional empty text for the table if resultset is empty
      )
      );
  $html .= '</div>';
  $html .= theme('pager',
      array(
            'tags' => array()
      )
      );
  return ($html); 
  
  $html .= '<br>出资人（个人）列表<br>';
  $query = "SELECT id, registered_name FROM " .
           "{fund_basic_information} where id = ?";
  $queryResult = db_query($query, array($fund_id));
  foreach($queryResult as $result){
  	$html .= '当前基金：' . '&nbsp;&nbsp;'. $result->registered_name.'<br><br>';
  }
  $html .= '<div id="printable_div">';
  $round_num = 1;
  $header = array(
      array('data' => '序号'),
      array('data' => '出资人', 'field' => 'geren_name'),
      array('data' => '出资人属性', 'field' => 'company_type'),
      array('data' => '承诺出资金额/认购总股本(万元)', 'field' => 'promise_amount'),
      array('data' => '占股比例', 'field' => 'percentage'),
      array('data' => '详情', 'field' => 'more'),
      );
  $query = db_select('chuziren_geren_info', 'n')
      ->extend('PagerDefault') //Pager Extender
      ->limit(20)//20 results per page
      ->extend('TableSort')//Sorting Extender
      ->orderByHeader($header)//Field to sort on is picked from $header
      ->fields ('n', array (
      'id',
      'geren_name',
      'promise_amount',
      'promise_bili',
      ))
	  ->condition('fund_id',$fund_id,'=');
  $results = $query
      ->execute();

  $rows = array();
  $_serial_num = 1;
  foreach ($results as $node) {
      $rows[] = array(
      'data' => array(
        $_serial_num,
        $node->geren_name,
        '个人',
        $node->promise_amount,
        $node->promise_bili,
         l('查看详情', 'chuziren_geren/list/'. $node->id),
      )
      );
	  $_serial_num +=1;
  }
  $html .= theme('table', 
      array(
            'header' => $header,
            'rows'=>$rows,
            //'caption' => '反馈意见列表',//Optional Caption for the table
            'sticky' => TRUE,//Optional to indicate whether the table headers should be sticky
            'empty' => '没有出资人信息',//Optional empty text for the table if resultset is empty
      )
      );
  $html .= '</div>';
  $html .= theme('pager',
      array(
            'tags' => array()
      )
      );
    
  return ($html); 
}
//传人出资人id
function chuziren_per_page($perid) {
 $query = "SELECT * FROM " .
           "{chuziren_info} where id = ?";
  $queryResult = db_query($query, array($perid));  
  $result = array();
  $fund_id = "";
  foreach($queryResult as $result){
  	$fund_id = $result->fund_id;
  }
  // content variable that will be returned for display';  
  drupal_set_title('出资人信息');
	 
  $html = "";
  if(user_access('jijingguanligongsi manage')){
  	$html .= l('返回列表','chuziren/fund/') . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'; 
  	$html .= l('编辑','chuziren/edit/'.$perid) . '<br />'. '<br />'; 
  }
    
  else
  	$html .= l('返回列表','chuziren/fundlist/'.$fund_id) . '<br />'. '<br />';  
  $link1 = "";
  $link2 = "";
  $link3 = "";
  $link4 = "";
  if($result->url1 != ""){
  	 $link1 = l("营业执照", 'http://' .$_SERVER['HTTP_HOST'].'/sites/default/files/'.$result->url1);
  }
  if($result->url2 != ""){
  	 $link2 = l("税务登记证", 'http://' .$_SERVER['HTTP_HOST'].'/sites/default/files/'.$result->url2);
  }
  if($result->url3 != ""){
  	 $link3 = l("组织机构代码证", 'http://' .$_SERVER['HTTP_HOST'].'/sites/default/files/'.$result->url3);
  }
  if($result->url4 != ""){
  	 $link4 = l("法定代表人身份证", 'http://' .$_SERVER['HTTP_HOST'].'/sites/default/files/'.$result->url4);
  }
  $html .= "<table style='width: 600px'><tr><th colspan=2>出资人信息</th></tr>
  <tr><td style='width: 40%'>出资人名称</td><td>".$result->company_name."</td></tr>
  <tr><td>办公地址</td><td>".$result->address."</td></tr>
  <tr><td>法定代表人</td><td>".$result->fadingdaibiaoren."</td></tr>
  <tr><td>注册资本（万元）</td><td>".$result->zuce_money."</td></tr>
  <tr><td>净资产（万元）</td><td>".$result->company_money."</td></tr>
  <tr><td>出资人属性</td><td>".$result->company_type."</td></tr>
  <tr><td>成立时间</td><td>".format_date($result->timestamp, 'custom', 'Y-m-d')."</td></tr>
  <tr><td>承诺出资额（万元）</td><td>".$result->promise_amount."</td></tr>
  <tr><td>承诺出资比例</td><td>".$result->promise_bili."</td></tr>
  <tr><td>实际控制人或控股股东</td><td>".$result->konggu."</td></tr>
  <tr><td>联系人</td><td>".$result->lianxiren."</td></tr>
  <tr><td>联系人职务</td><td>".$result->lianxirenzhiwu."</td></tr>
  <tr><td>手机</td><td>".$result->mobile."</td></tr>
  <tr><td>电话</td><td>".$result->phone."</td></tr>
  <tr><td>传真</td><td>".$result->chuanzhen."</td></tr>
  <tr><td>联系邮箱</td><td>".$result->lianximail."</td></tr>
  <tr><td>出资人简介</td><td>".$result->company_info."</td></tr>
  <tr><td>备注</td><td>".$result->remark."</td></tr>
  <tr><td>营业执照</td><td>".$link1."</td></tr>
  <tr><td>税务登记证</td><td>".$link2."</td></tr>
  <tr><td>组织机构代码证</td><td>".$link3."</td></tr>
  <tr><td>法定代表人身份证</td><td>".$link4."</td></tr></table>";

	 //Drupal7的页面回调，返回的应该是一个数组
  return $html;
}

//传人出资人id
function chuziren_edit_page($perid) {
 
  // content variable that will be returned for display
  $page_content = '';
  $page_content .= l('返回列表','chuziren/fund') .'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'; 
  $page_content .= l('浏览','chuziren/view/'.$perid) . '<br />'. '<br />'; 
  drupal_set_title('管理该项出资人信息');
	 
  $render_array = array(
	   '#markup' => $page_content,
	 );
  global $user;
  $query = "SELECT id,registered_name FROM " .
           "{fund_basic_information} where user_id = ?";
  $queryResult = db_query($query, array($user->uid));
  $fund_id = 0;
  foreach ($queryResult as $result) {
     $fund_id = $result->id;
  }
	 //该页面的正文为一个表单，注意对于表单，这里需要使用drupal_render呈现一下。
  $form = drupal_get_form('chuziren_edit_form',$perid);
  $render_array['#markup'] .= drupal_render($form);
  
  $query = "SELECT fund_id FROM " .
           "{chuziren_info} where id = ?";
  $queryResult = db_query($query, array($perid));
  foreach ($queryResult as $result ) {
	if($result->fund_id != $fund_id){
		 drupal_goto('chuziren/fund');
	}
  }
	 //Drupal7的页面回调，返回的应该是一个数组
  return $render_array;
}

function chuziren_edit_form($form, &$form_state, $perid){
  $query = "SELECT * FROM " .
           "{chuziren_info} where id = ?";
  $queryResult = db_query($query, array($perid));
  $result = array();
  $empty = TRUE;
  $datetime = "";
  foreach ($queryResult as $result ) {
	$datetime = getdate($result->timestamp);
  }
   $form['bid'] = array('#type' => 'hidden', '#value' => $perid);
   $form['company_name'] = array(
	  '#title' => t('出资人名称'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['company_name'])?$_SESSION['chuziren_form']['company_name']:$result->company_name,
	 );
	 $form['address'] = array(
	  '#title' => t('办公地址'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['address'])?$_SESSION['chuziren_form']['address']:$result->address,
	 );
	 $form['fadingdaibiaoren'] = array(
	  '#title' => t('法定代表人'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['fadingdaibiaoren'])?$_SESSION['chuziren_form']['fadingdaibiaoren']:$result->fadingdaibiaoren,
	 );
	  $form['zuce_money'] = array(
	  '#title' => t('注册资本（万元）'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['zuce_money'])?$_SESSION['chuziren_form']['zuce_money']:$result->zuce_money,
	 );
	 $form['company_money'] = array(
	  '#title' => t('净资产（万元）'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['company_money'])?$_SESSION['chuziren_form']['company_money']:$result->company_money,
	  '#description' => t('例如：250.55'),
	 );
	 $form['company_type'] = array(
	  '#title' => t('出资人属性(政府/私企/国企)'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['company_type'])?$_SESSION['chuziren_form']['company_type']:$result->company_type,
	 ); 

     $form['timestamp'] = array(
	     '#type' => 'date', // types 'date_popup', 'date_text' and 'date_timezone' are also supported. See .inc file.
	     '#title' => t('成立时间'),
	     '#default_value' => array('year' =>  $datetime['year'], 'month' =>  $datetime['mon'], 'day' => $datetime['mday']), 
	  );
	  $form['promise_amount'] = array(
	  '#title' => t('承诺出资额（万元）'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['promise_amount'])?$_SESSION['chuziren_form']['promise_amount']:$result->promise_amount,
	 );
	  $form['promise_bili'] = array(
	  '#title' => t('承诺出资比例'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['promise_bili'])?$_SESSION['chuziren_form']['promise_bili']:$result->promise_bili,
	 );
	 $form['konggu'] = array(
	  '#title' => t('实际控制人或控股股东'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['konggu'])?$_SESSION['chuziren_form']['konggu']:$result->konggu,
	 ); 
	 $form['lianxiren'] = array(
	  '#title' => t('联系人'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['lianxiren'])?$_SESSION['chuziren_form']['lianxiren']:$result->lianxiren,
	 ); 
	  $form['lianxirenzhiwu'] = array(
	  '#title' => t('联系人职务'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['lianxirenzhiwu'])?$_SESSION['chuziren_form']['lianxirenzhiwu']:$result->lianxirenzhiwu,
	 ); 
	  $form['mobile'] = array(
	  '#title' => t('手机'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['mobile'])?$_SESSION['chuziren_form']['mobile']:$result->mobile,
	 ); 
	  $form['phone'] = array(
	  '#title' => t('电话'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['phone'])?$_SESSION['chuziren_form']['phone']:$result->phone,
	 ); 
	  $form['chuanzhen'] = array(
	  '#title' => t('传真'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['chuanzhen'])?$_SESSION['chuziren_form']['chuanzhen']:$result->chuanzhen,
	 ); 
	  $form['lianximail'] = array(
	  '#title' => t('联系邮箱'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['lianximail'])?$_SESSION['chuziren_form']['lianximail']:$result->lianximail,
	 ); 
  	 $form['company_info'] = array(
	  '#title' => t('出资人简介'),
	  '#type' => 'textarea',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['company_info'])?$_SESSION['chuziren_form']['company_info']:$result->company_info,
	 );
	 $form['remark'] = array(
	  '#title' => t('备注'),
	  '#type' => 'textarea',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_form']['remark'])?$_SESSION['chuziren_form']['remark']:$result->remark,
	 );
	 $form['upload1'] = array(
		'#type' => 'managed_file',
		'#title' => '重新提交营业执照',
		'#required' => FALSE,
		'#upload_location' => 'public://my_uploads',
		'#upload_validators' => array(
	    'file_validate_extensions' => array('doc xls pdf docx xlsx zip tar.gz 7z'),
		'file_validate_size' => array(20*1024*1024)),
	);
	$form['upload2'] = array(
		'#type' => 'managed_file',
		'#title' => '重新提交税务登记证',
		'#required' => FALSE,
		'#upload_location' => 'public://my_uploads',
		'#upload_validators' => array(
	    'file_validate_extensions' => array('doc xls pdf docx xlsx zip tar.gz 7z'),
		'file_validate_size' => array(20*1024*1024)),
	);
	$form['upload3'] = array(
		'#type' => 'managed_file',
		'#title' => '重新提交组织机构代码证',
		'#required' => FALSE,
		'#upload_location' => 'public://my_uploads',
		'#upload_validators' => array(
	    'file_validate_extensions' => array('doc xls pdf docx xlsx zip tar.gz 7z'),
		'file_validate_size' => array(20*1024*1024)),
	);
	$form['upload4'] = array(
		'#type' => 'managed_file',
		'#title' => '重新提交法定代表人身份证',
		'#required' => FALSE,
		'#upload_location' => 'public://my_uploads',
		'#upload_validators' => array(
	    'file_validate_extensions' => array('doc xls pdf docx xlsx zip tar.gz 7z'),
		'file_validate_size' => array(20*1024*1024)),
	);
	  $form['submit'] = array(
	    '#type' => 'submit',
	    '#value' => t('提交修改'),
	  );
	  
	 //表单元素“提交”按钮
	  $form['deleate'] = array(
	    '#type' => 'submit',
	    '#value' => t('删除该出资人信息'),
	    '#submit' => array('chuziren_edit_form_deleate'),
	  );
  
  
  return $form;
}

function chuziren_edit_form_submit($form, &$form_state){
	  $values = NULL;
	  $values = $form_state['values'];
      $datetime = mktime(0, 0, 0,$values['timestamp']['month'], $values['timestamp']['day'], $values['timestamp']['year']);
	  db_update('chuziren_info')
  		->fields(array(
   			 'company_name' => $values['company_name'],
   			 'address' => $values['address'],
   			 'fadingdaibiaoren' => $values['fadingdaibiaoren'],
   			 'company_money' => $values['company_money'],
   			 'zuce_money' => $values['zuce_money'],
   			 'company_type' => $values['company_type'],
   			 'timestamp' =>  $datetime,
   			 'promise_amount' => $values['promise_amount'],
   			 'promise_bili' => $values['promise_bili'],
   			 'konggu' => $values['konggu'],
			 'lianxiren' => $values['lianxiren'],
			 'lianxirenzhiwu' => $values['lianxirenzhiwu'],
			 'mobile' => $values['mobile'],
			 'phone' => $values['phone'],
			 'chuanzhen' => $values['chuanzhen'],
			 'lianximail' => $values['lianximail'],
   			 'company_info' => $values['company_info'],
   			 'remark' => $values['remark'],
  			))
  		->condition('id', $values['bid'])
  		->execute();
	  		
	  		$fid = $form_state['values']['upload1']; 
			$file = file_load($fid);  			
			if ($file != null) {
				$saveurl = file_uri_target($file->uri);
				$fid = $file->fid;   
				//$extension_errors=file_validate_extensions($file, "jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp docx");   
			    $extension_errors=file_validate_extensions($file, "doc xls pdf docx xlsx zip tar.gz 7z");   
				if (!$extension_errors) {  
					$file->status = FILE_STATUS_PERMANENT;   
					file_save($file);			
						db_update('chuziren_info')
					  		->fields(array(
					   			 'url1' => $saveurl,					   			
					   			 'file_managed_id1' => $fid,
					  		     ))->execute();
				} 
				else {
				form_set_error('upload',$extension_errors[0]); 
				}
			}

			$fid = $form_state['values']['upload2']; 
			$file = file_load($fid);  
			
			if ($file != null) {
				$saveurl = file_uri_target($file->uri);
				$fid = $file->fid;   
				//$extension_errors=file_validate_extensions($file, "jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp docx");   
			    $extension_errors=file_validate_extensions($file, "doc xls pdf docx xlsx zip tar.gz 7z");   
				if (!$extension_errors) {  
					$file->status = FILE_STATUS_PERMANENT;   
					file_save($file);			
						db_update('chuziren_info')
					  		->fields(array(
					   			 'url2' => $saveurl,					   			
					   			 'file_managed_id2' => $fid,
					  		     ))->execute();
				} 
				else {
				form_set_error('upload',$extension_errors[0]); 
				}
			}
			
			$fid = $form_state['values']['upload3']; 
			$file = file_load($fid);  
			
			if ($file != null) {
				$saveurl = file_uri_target($file->uri);
				$fid = $file->fid;   
				//$extension_errors=file_validate_extensions($file, "jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp docx");   
			    $extension_errors=file_validate_extensions($file, "doc xls pdf docx xlsx zip tar.gz 7z");   
				if (!$extension_errors) {  
					$file->status = FILE_STATUS_PERMANENT;   
					file_save($file);			
						db_update('chuziren_info')
					  		->fields(array(
					   			 'url3' => $saveurl,					   			
					   			 'file_managed_id3' => $fid,
					  		     ))->execute();
				} 
				else {
				form_set_error('upload',$extension_errors[0]); 
				}
			}
			
			$fid = $form_state['values']['upload4']; 
			$file = file_load($fid);  
			
			if ($file != null) {
				$saveurl = file_uri_target($file->uri);
				$fid = $file->fid;   
				//$extension_errors=file_validate_extensions($file, "jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp docx");   
			    $extension_errors=file_validate_extensions($file, "doc xls pdf docx xlsx zip tar.gz 7z");   
				if (!$extension_errors) {  
					$file->status = FILE_STATUS_PERMANENT;   
					file_save($file);			
						db_update('chuziren_info')
					  		->fields(array(
					   			 'url4' => $saveurl,					   			
					   			 'file_managed_id4' => $fid,
					  		     ))->execute();
				} 
				else {
				form_set_error('upload',$extension_errors[0]); 
				}
			}
	 $form_state['redirect'] = 'chuziren/list/'.$values['bid'];
}

function chuziren_edit_form_deleate($form, &$form_state){
	 $values = NULL;
	 $_SESSION['chuziren_edit_form'] = $form_state['values'];
	 $values = $_SESSION['chuziren_edit_form'] ;
	 //表单重定向到确认页面
	 $form_state['redirect'] = 'chuziren/deleate/'.$values['bid'];
}

function chuziren_deleate_page($perid) {
  // content variable that will be returned for display
  $page_content = '删除后该出资人信息将不可恢复！';
  
  drupal_set_title('删除该出资人信息');
	 
	 $render_array = array(
	   '#markup' => $page_content,
	 );
	 
	 //该页面的正文为一个表单，注意对于表单，这里需要使用drupal_render呈现一下。
	 $form = drupal_get_form('chuziren_deleate_form');
	 $render_array['#markup'] .= drupal_render($form);
	 
	 //Drupal7的页面回调，返回的应该是一个数组
  return $render_array;

}

function chuziren_deleate_form($form, &$form_state){
 //表单元素“返回”按钮
  $form['back'] = array(
    '#type' => 'submit',
    '#value' => t('取消'),
    '#submit' => array('chuziren_deleate_form_back'),
  );
 //表单元素“提交”按钮
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('删除'),
  );
  
  return $form;
}

function chuziren_deleate_form_back($form, &$form_state){
	if(empty($_SESSION['chuziren_edit_form'])){
		  //drupal_goto('contact');
		  $form_state['redirect'] = 'chuziren/fundlist';
	  }else{
		  $values = $_SESSION['chuziren_edit_form'];
		  unset($_SESSION['chuziren_edit_form']);
		  $form_state['redirect'] = 'chuziren/list/'.$values['bid'];
	  }
}

function chuziren_deleate_form_submit($form, &$form_state){
  //简单的重定向到contactus页面
 if(empty($_SESSION['chuziren_edit_form'])){
		  //drupal_goto('contact');
		  $form_state['redirect'] = 'chuziren/fundlist';
	  }else{
		  $values = $_SESSION['chuziren_edit_form'];
		  unset($_SESSION['chuziren_edit_form']);
		  db_delete('chuziren_info')
			->condition('id' ,$values['bid'])
			->execute();
		  $form_state['redirect'] = 'chuziren/fundlist';;
	  }

}

function chuziren_fund_page(){
  global $user;
  $query = "SELECT id, registered_name FROM " .
           "{fund_basic_information} where user_id = ?";
  $queryResult = db_query($query, array($user->uid));
  $fund_id =0;
  $html = "";
  foreach($queryResult as $result){
  	$html .= '基金名称' . '&nbsp;&nbsp;'. $result->registered_name.'<br><br>';
	$fund_id = $result->id;
  }
  //$html .= l('添加出资人(公司)信息','chuziren/create/') .  '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  //$html .= l('添加出资人（个人）信息','chuziren_geren/create/') .  '<br />';
  $html .= l('添加出资人','chuziren/create_confirm/') .  '<br /><br />';
  //$html .= '<br>出资人（公司）列表<br>';

  $header = array(
      array('data' => '序号'),
      array('data' => '出资人', 'field' => 'company_name'),
      array('data' => '出资人属性', 'field' => 'company_type'),
      array('data' => '承诺出资金额/认购总股本(万元)', 'field' => 'promise_amount'),
      array('data' => '占股比例', 'field' => 'percentage'),
      array('data' => '详情', 'field' => 'more'),
      );
  $query = db_select('chuziren_info', 'n')
      ->extend('PagerDefault') //Pager Extender
      ->limit(20)//20 results per page
      ->extend('TableSort')//Sorting Extender
      ->orderByHeader($header)//Field to sort on is picked from $header
      ->fields ('n', array (
      'id',
      'company_name',
      'company_type',
      'promise_amount',
      'promise_bili',
      ))
	  ->condition('fund_id',$fund_id,'=');
  $results = $query
      ->execute();

  $rows = array();
  $_serial_num = 1;
  foreach ($results as $node) {
      $rows[] = array(
      'data' => array(
        $_serial_num,
        $node->company_name,
        $node->company_type,
        $node->promise_amount,
        $node->promise_bili,
         l('查看详情', 'chuziren/list/'. $node->id),
      )
      );
	  $_serial_num +=1;
  }
   $query = db_select('chuziren_geren_info', 'n')
      ->extend('PagerDefault') //Pager Extender
      ->limit(20)//20 results per page
      ->extend('TableSort')//Sorting Extender
      ->orderByHeader($header)//Field to sort on is picked from $header
      ->fields ('n', array (
      'id',
      'geren_name',
      'promise_amount',
      'promise_bili',
      ))
	  ->condition('fund_id',$fund_id,'=');
  $results = $query
      ->execute();

 // $rows = array();
  //$_serial_num = 1;
  foreach ($results as $node) {
      $rows[] = array(
      'data' => array(
        $_serial_num,
        $node->geren_name,
        '个人',
        $node->promise_amount,
        $node->promise_bili,
         l('查看详情', 'chuziren_geren/list/'. $node->id),
      )
      );
	  $_serial_num +=1;
  }
  $html .= theme('table', 
      array(
            'header' => $header,
            'rows'=>$rows,
            //'caption' => '反馈意见列表',//Optional Caption for the table
            'sticky' => TRUE,//Optional to indicate whether the table headers should be sticky
            'empty' => '没有出资人信息',//Optional empty text for the table if resultset is empty
      )
      );
  $html .= '</div>';
  $html .= theme('pager',
      array(
            'tags' => array()
      )
      );
  return ($html);   
  $html .= '<br>出资人（个人）列表<br>';
  $header = array(
      array('data' => '序号'),
      array('data' => '出资人', 'field' => 'geren_name'),
      array('data' => '出资人属性', 'field' => 'company_type'),
      array('data' => '承诺出资金额/认购总股本(万元)', 'field' => 'promise_amount'),
      array('data' => '占股比例', 'field' => 'percentage'),
      array('data' => '详情', 'field' => 'more'),
      );
  $query = db_select('chuziren_geren_info', 'n')
      ->extend('PagerDefault') //Pager Extender
      ->limit(20)//20 results per page
      ->extend('TableSort')//Sorting Extender
      ->orderByHeader($header)//Field to sort on is picked from $header
      ->fields ('n', array (
      'id',
      'geren_name',
      'promise_amount',
      'promise_bili',
      ))
	  ->condition('fund_id',$fund_id,'=');
  $results = $query
      ->execute();

  $rows = array();
  $_serial_num = 1;
  foreach ($results as $node) {
      $rows[] = array(
      'data' => array(
        $_serial_num,
        $node->geren_name,
        '个人',
        $node->promise_amount,
        $node->promise_bili,
         l('查看详情', 'chuziren_geren/list/'. $node->id),
      )
      );
	  $_serial_num +=1;
  }
  $html .= theme('table', 
      array(
            'header' => $header,
            'rows'=>$rows,
            //'caption' => '反馈意见列表',//Optional Caption for the table
            'sticky' => TRUE,//Optional to indicate whether the table headers should be sticky
            'empty' => '没有出资人信息',//Optional empty text for the table if resultset is empty
      )
      );
  $html .= '</div>';
  $html .= theme('pager',
      array(
            'tags' => array()
      )
      );
  
  return ($html); 
}
//出资人设置基金选择入口
function chuziren_fundlist_page() {
 $html = '';
 
 if(user_access('jijingguanligongsi manage')){
 	//drupal_goto('chuziren/fund');
 }
 
 $header = array(
      array('data' => '基金名称', 'field' => 'registered_name', 'sort' => 'desc'),
      array('data' => '联系人', 'field' => 'contact'),
      array('data' => '出资人管理', 'field' => 'chuziren_set'),
      );
  $query = db_select('fund_basic_information', 'n')
      ->extend('PagerDefault') //Pager Extender
      ->limit(15)//10 results per page
      ->extend('TableSort')//Sorting Extender
      ->orderByHeader($header)//Field to sort on is picked from $header
      ->fields ('n', array (
      'id',
      'registered_name',
      'contact',
      ));
  $results = $query
      ->execute();

  $rows = array();
  foreach ($results as $node) {
          $title = l('进入', 'chuziren/fundlist/'.$node->id);
		  $rows[] = array(
	      'data' => array(
	        $node->registered_name,
	        $node->contact,
	        $title,
	      )
	      );
  }
  $html .= theme('table', 
      array(
            'header' => $header,
            'rows'=>$rows,
            //'caption' => '反馈意见列表',//Optional Caption for the table
            'sticky' => TRUE,//Optional to indicate whether the table headers should be sticky
            'empty' => '没有基金信息',//Optional empty text for the table if resultset is empty
      )
      );
  $html .= theme('pager',
      array(
            'tags' => array()
      )
      );
  return ($html); 
}

/////////////////
//出资人（个人）管理
/////////////////
function chuziren_geren_create(){
	  //我们为这个页面设置标题
	drupal_set_title('新增出资人信息');
	global $user;
	$query = "SELECT id,registered_name FROM " .
           "{fund_basic_information} where user_id = ?";
    $queryResult = db_query($query, array($user->uid));
	$fund_id = 0;
    foreach ($queryResult as $result) {
    	$fund_id = $result->id;
		$page_content = l('返回列表','chuziren/fund') . '<br />'. '<br />';
    	 $page_content .= '当前基金：' . '&nbsp;&nbsp;'. $result->registered_name.'<br><br>';
	}
	if ($fund_id==0){
		drupal_goto('chuziren/fund');
	}
	 
	 $render_array = array(
	   '#markup' => $page_content, 
	 );
	 
	 $form = drupal_get_form('chuziren_geren_form',$fund_id);
	 $render_array['#markup'] .= drupal_render($form);
	 
	 return $render_array;
}

function chuziren_geren_form($form, &$form_state, $fund_id){
	 $form['bid'] = array('#type' => 'hidden', '#value' => $fund_id);
	 
	 $form['tips'] = array(
	  '#prefix' =>'<div id="tips">',
	  '#markup' => t('<span class="form-required">*</span> 号为必填项。'),
	  '#suffix' =>'</div>',
	 );
	 
	 $form['geren_name'] = array(
	  '#title' => t('出资人姓名'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['geren_name'])?$_SESSION['chuziren_geren_form']['geren_name']:"",
	 );
	  $form['xingbie'] = array(
	  '#title' => t('性别'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['xingbie'])?$_SESSION['chuziren_geren_form']['xingbie']:"",
	 );
	  $form['guoji'] = array(
	  '#title' => t('国籍'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['guoji'])?$_SESSION['chuziren_geren_form']['guoji']:"",
	 );
	 $form['chushengnianyue'] = array(
	  '#title' => t('出生年月日'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['chushengnianyue'])?$_SESSION['chuziren_geren_form']['chushengnianyue']:"",
	 );
	 $form['address'] = array(
	  '#title' => t('办公地址'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['address'])?$_SESSION['chuziren_geren_form']['address']:"",
	 );
	 $form['mobile'] = array(
	  '#title' => t('手机'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['mobile'])?$_SESSION['chuziren_geren_form']['mobile']:"",
	 ); 
	  $form['phone'] = array(
	  '#title' => t('电话'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['phone'])?$_SESSION['chuziren_geren_form']['phone']:"",
	 ); 
	  $form['lianximail'] = array(
	  '#title' => t('联系邮箱'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['lianximail'])?$_SESSION['chuziren_geren_form']['lianximail']:"",
	 ); 
	  $form['shenfenzhenghao'] = array(
	  '#title' => t('身份证号'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['shenfenzhenghao'])?$_SESSION['chuziren_geren_form']['shenfenzhenghao']:"",
	 ); 
  	  $form['tongxun_address'] = array(
	  '#title' => t('通讯地址'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['tongxun_address'])?$_SESSION['chuziren_geren_form']['tongxun_address']:"",
	 );
	  $form['youbian'] = array(
	  '#title' => t('邮编'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['youbian'])?$_SESSION['chuziren_geren_form']['youbian']:"",
	 );
	  $form['promise_amount'] = array(
	  '#title' => t('承诺出资额（万元）'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['promise_amount'])?$_SESSION['chuziren_geren_form']['promise_amount']:"",
	 );
	 $form['promise_bili'] = array(
	  '#title' => t('承诺出资比例'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['promise_bili'])?$_SESSION['chuziren_geren_form']['promise_bili']:"",
	 );
	  $form['jiaoyu_info'] = array(
	  '#title' => t('教育经历（要求时间连续）'),
	  '#type' => 'textarea',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['jiaoyu_info'])?$_SESSION['chuziren_geren_form']['jiaoyu_info']:"",
	 );
	  $form['gongzuo_info'] = array(
	  '#title' => t('工作经历及任职情况（要求时间连续）'),
	  '#type' => 'textarea',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['gongzuo_info'])?$_SESSION['chuziren_geren_form']['gongzuo_info']:"",
	 );
	  $form['jiangli_info'] = array(
	  '#title' => t('受过何等奖励及处分'),
	  '#type' => 'textarea',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['jiangli_info'])?$_SESSION['chuziren_geren_form']['jiangli_info']:"",
	 );
	 $form['remark'] = array(
	  '#title' => t('备注'),
	  '#type' => 'textarea',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['remark'])?$_SESSION['chuziren_geren_form']['remark']:"",
	 );	
	  $form['submit'] = array(
	    '#type' => 'submit',
	    '#value' => t('确认'),
	  );
	  return $form;
}

function chuziren_geren_form_validate($form, &$form_state){
	  if (drupal_strlen($form_state['values']['promise_amount']) > 10) {
	    form_set_error('promise_amount', '要求精度小于10 个字符');
	  } 
	  if (!($form_state['values']['promise_amount']>0)) {
	    form_set_error('promise_amount', '请输入正数');
	  } 
	  
}

function chuziren_geren_form_submit($form, &$form_state){
	  //把表单的值存放在会话中去，由于这里涉及到了两个不同的表单之间传值。
	// $_SESSION['chuziren_geren_form'] = $form_state['values'];
	 //表单重定向到确认页面
	 //$form_state['redirect'] = 'chuziren_geren/confirm';
	  	 
	$values=$form_state['values'];	
    $last_id = db_insert('chuziren_geren_info')
  		->fields(array(
  		     'fund_id' => $values['bid'],
   			 'geren_name' => $values['geren_name'],
   			 'xingbie' => $values['xingbie'],
   			 'guoji' => $values['guoji'],
   			 'chushengnianyue' => $values['chushengnianyue'],
   			 'address' => $values['address'],
   			 'mobile' => $values['mobile'],
   			 'phone' => $values['phone'],
   			 'lianximail' => $values['lianximail'],
   			 'shenfenzhenghao' => $values['shenfenzhenghao'],
			 'tongxun_address' => $values['tongxun_address'],
			 'youbian' => $values['youbian'],
			 'promise_amount' => $values['promise_amount'],
			 'promise_bili' => $values['promise_bili'],
			 'jiaoyu_info' => $values['jiaoyu_info'],
			 'gongzuo_info' => $values['gongzuo_info'],
   			 'jiangli_info' => $values['jiangli_info'],
   			 'remark' => $values['remark'],
  			))->execute();
	  if ($last_id!=NULL) {				
			 $form_state['redirect'] = 'chuziren/fund';
	  } else {	    
	    // 数据写入失败了
	      drupal_set_message('抱歉，遇到问题，提交失败了', 'error');
	    
	  }	
}
 
//传人出资人id
function chuziren_geren_per_page($perid) {
 $query = "SELECT * FROM " .
           "{chuziren_geren_info} where id = ?";
  $queryResult = db_query($query, array($perid));  
  $result = array();
  
  foreach($queryResult as $result){
  	
  }
  // content variable that will be returned for display';  
  drupal_set_title('出资人信息');
	 
  $html = "";
  if(user_access('jijingguanligongsi manage')){
  	$html .= l('返回列表','chuziren/fund/') . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'; 
  	$html .= l('编辑','chuziren_geren/edit/'.$perid) . '<br />'. '<br />'; 
  }
    
  else
  	$html .= l('返回列表','chuziren/fundlist/'.$result->fund_id) . '<br />'. '<br />';  
 
  $html .= "<table style='width: 600px'><tr><th colspan=2>出资人信息</th></tr>
  <tr><td style='width: 40%'>出资人名称</td><td>".$result->geren_name."</td></tr>
  <tr><td>性别</td><td>".$result->xingbie."</td></tr>
  <tr><td>国籍</td><td>".$result->guoji."</td></tr>
  <tr><td>出生年月日</td><td>".$result->chushengnianyue."</td></tr>
  <tr><td>办公地址</td><td>".$result->address."</td></tr>
  <tr><td>手机</td><td>".$result->mobile."</td></tr>
  <tr><td>电话</td><td>".$result->phone."</td></tr>
  <tr><td>联系邮箱</td><td>".$result->lianximail."</td></tr>
  <tr><td>身份证号</td><td>".$result->shenfenzhenghao."</td></tr>
  <tr><td>通讯地址</td><td>".$result->tongxun_address."</td></tr>
  <tr><td>邮编</td><td>".$result->youbian."</td></tr>
  <tr><td>承诺出资额（万元）</td><td>".$result->promise_amount."</td></tr>
  <tr><td>承诺出资比例</td><td>".$result->promise_bili."</td></tr>
  <tr><td>教育经历（要求时间连续）</td><td>".$result->jiaoyu_info."</td></tr>
  <tr><td>工作经历及任职情况（要求时间连续）</td><td>".$result->gongzuo_info."</td></tr>
  <tr><td>受过何等奖励及处分</td><td>".$result->jiangli_info."</td></tr>
  <tr><td>备注</td><td>".$result->remark."</td></tr></table>";
	 //Drupal7的页面回调，返回的应该是一个数组
  return $html;
}

//传人出资人id
function chuziren_geren_edit_page($perid) {
 
  // content variable that will be returned for display
  $page_content = '';
  $page_content .= l('返回列表','chuziren/fund') .'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'; 
  $page_content .= l('浏览','chuziren_geren/view/'.$perid) . '<br />'. '<br />'; 
  drupal_set_title('管理该项出资人信息');
	 
  $render_array = array(
	   '#markup' => $page_content,
	 );
  global $user;
  $query = "SELECT id,registered_name FROM " .
           "{fund_basic_information} where user_id = ?";
  $queryResult = db_query($query, array($user->uid));
  $fund_id = 0;
  foreach ($queryResult as $result) {
     $fund_id = $result->id;
  }
	 //该页面的正文为一个表单，注意对于表单，这里需要使用drupal_render呈现一下。
  $form = drupal_get_form('chuziren_geren_edit_form',$perid);
  $render_array['#markup'] .= drupal_render($form);
  
  $query = "SELECT fund_id FROM " .
           "{chuziren_geren_info} where id = ?";
  $queryResult = db_query($query, array($perid));
  foreach ($queryResult as $result ) {
	if($result->fund_id != $fund_id){
		 drupal_goto('chuziren/fund');
	}
  }
	 //Drupal7的页面回调，返回的应该是一个数组
  return $render_array;
}

function chuziren_geren_edit_form($form, &$form_state, $perid){
  $query = "SELECT * FROM " .
           "{chuziren_geren_info} where id = ?";
  $queryResult = db_query($query, array($perid));
  $result = array();
  foreach ($queryResult as $result ) {
	
  }
   $form['bid'] = array('#type' => 'hidden', '#value' => $perid);
  $form['geren_name'] = array(
	  '#title' => t('出资人姓名'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['geren_name'])?$_SESSION['chuziren_geren_form']['geren_name']:$result->geren_name,
	 );
	  $form['xingbie'] = array(
	  '#title' => t('性别'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['xingbie'])?$_SESSION['chuziren_geren_form']['xingbie']:$result->xingbie,
	 );
	  $form['guoji'] = array(
	  '#title' => t('国籍'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['guoji'])?$_SESSION['chuziren_geren_form']['guoji']:$result->guoji,
	 );
	 $form['chushengnianyue'] = array(
	  '#title' => t('出生年月日'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['chushengnianyue'])?$_SESSION['chuziren_geren_form']['chushengnianyue']:$result->chushengnianyue,
	 );
	 $form['address'] = array(
	  '#title' => t('家庭地址'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['address'])?$_SESSION['chuziren_geren_form']['address']:$result->address,
	 );
	 $form['mobile'] = array(
	  '#title' => t('手机'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['mobile'])?$_SESSION['chuziren_geren_form']['mobile']:$result->mobile,
	 ); 
	  $form['phone'] = array(
	  '#title' => t('电话'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['phone'])?$_SESSION['chuziren_geren_form']['phone']:$result->phone,
	 ); 
	  $form['lianximail'] = array(
	  '#title' => t('联系邮箱'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['lianximail'])?$_SESSION['chuziren_geren_form']['lianximail']:$result->lianximail,
	 ); 
	  $form['shenfenzhenghao'] = array(
	  '#title' => t('身份证号'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['shenfenzhenghao'])?$_SESSION['chuziren_geren_form']['shenfenzhenghao']:$result->shenfenzhenghao,
	 ); 
  	  $form['tongxun_address'] = array(
	  '#title' => t('通讯地址'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['tongxun_address'])?$_SESSION['chuziren_geren_form']['tongxun_address']:$result->tongxun_address,
	 );
	  $form['youbian'] = array(
	  '#title' => t('邮编'),
	  '#type' => 'textfield',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['youbian'])?$_SESSION['chuziren_geren_form']['youbian']:$result->youbian,
	 );
	  $form['promise_amount'] = array(
	  '#title' => t('承诺出资额（万元）'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['promise_amount'])?$_SESSION['chuziren_geren_form']['promise_amount']:$result->promise_amount,
	 );
	 $form['promise_bili'] = array(
	  '#title' => t('承诺出资比例'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['promise_bili'])?$_SESSION['chuziren_geren_form']['promise_bili']:$result->promise_bili,
	 );
	  $form['jiaoyu_info'] = array(
	  '#title' => t('教育经历（要求时间连续）'),
	  '#type' => 'textarea',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['jiaoyu_info'])?$_SESSION['chuziren_geren_form']['jiaoyu_info']:$result->jiaoyu_info,
	 );
	  $form['gongzuo_info'] = array(
	  '#title' => t('工作经历及任职情况（要求时间连续）'),
	  '#type' => 'textarea',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['gongzuo_info'])?$_SESSION['chuziren_geren_form']['gongzuo_info']:$result->gongzuo_info,
	 );
	  $form['jiangli_info'] = array(
	  '#title' => t('受过何等奖励及处分'),
	  '#type' => 'textarea',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['jiangli_info'])?$_SESSION['chuziren_geren_form']['jiangli_info']:$result->jiangli_info,
	 );
	 $form['remark'] = array(
	  '#title' => t('备注'),
	  '#type' => 'textarea',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['chuziren_geren_form']['remark'])?$_SESSION['chuziren_geren_form']['remark']:$result->remark,
	 );	
	  $form['submit'] = array(
	    '#type' => 'submit',
	    '#value' => t('提交修改'),
	  );
	  
	 //表单元素“提交”按钮
	  $form['deleate'] = array(
	    '#type' => 'submit',
	    '#value' => t('删除该出资人信息'),
	    '#submit' => array('chuziren_geren_edit_form_deleate'),
	  );
  
  
  return $form;
}

function chuziren_geren_edit_form_submit($form, &$form_state){
	  $values = NULL;
	  $values = $form_state['values'];
      db_update('chuziren_geren_info')
  		->fields(array(
   			 'geren_name' => $values['geren_name'],
   			 'xingbie' => $values['xingbie'],
   			 'guoji' => $values['guoji'],
   			 'chushengnianyue' => $values['chushengnianyue'],
   			 'address' => $values['address'],
   			 'mobile' => $values['mobile'],
   			 'phone' => $values['phone'],
   			 'lianximail' => $values['lianximail'],
   			 'shenfenzhenghao' => $values['shenfenzhenghao'],
			 'tongxun_address' => $values['tongxun_address'],
			 'youbian' => $values['youbian'],
			 'promise_amount' => $values['promise_amount'],
			 'promise_bili' => $values['promise_bili'],
			 'jiaoyu_info' => $values['jiaoyu_info'],
			 'gongzuo_info' => $values['gongzuo_info'],
   			 'jiangli_info' => $values['jiangli_info'],
   			 'remark' => $values['remark'],
  			))
  		->condition('id', $values['bid'])
  		->execute();
	 
	 $form_state['redirect'] = 'chuziren_geren/list/'.$values['bid'];
}

function chuziren_geren_edit_form_deleate($form, &$form_state){
	 $values = NULL;
	 $_SESSION['chuziren_geren_edit_form'] = $form_state['values'];
	 $values = $_SESSION['chuziren_geren_edit_form'] ;
	 //表单重定向到确认页面
	 $form_state['redirect'] = 'chuziren_geren/deleate/'.$values['bid'];
}

function chuziren_geren_deleate_page($perid) {
  // content variable that will be returned for display
  $page_content = '删除后该出资人信息将不可恢复！';
  
  drupal_set_title('删除该出资人信息');
	 
	 $render_array = array(
	   '#markup' => $page_content,
	 );
	 
	 //该页面的正文为一个表单，注意对于表单，这里需要使用drupal_render呈现一下。
	 $form = drupal_get_form('chuziren_geren_deleate_form');
	 $render_array['#markup'] .= drupal_render($form);
	 
	 //Drupal7的页面回调，返回的应该是一个数组
  return $render_array;

}

function chuziren_geren_deleate_form($form, &$form_state){
 //表单元素“返回”按钮
  $form['back'] = array(
    '#type' => 'submit',
    '#value' => t('取消'),
    '#submit' => array('chuziren_geren_deleate_form_back'),
  );
 //表单元素“提交”按钮
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('删除'),
  );
  
  return $form;
}

function chuziren_geren_deleate_form_back($form, &$form_state){
	if(empty($_SESSION['chuziren_geren_edit_form'])){
		  //drupal_goto('contact');
		  $form_state['redirect'] = 'chuziren/fundlist';
	  }else{
		  $values = $_SESSION['chuziren_geren_edit_form'];
		  unset($_SESSION['chuziren_geren_edit_form']);
		  $form_state['redirect'] = 'chuziren_geren/list/'.$values['bid'];
	  }
}

function chuziren_geren_deleate_form_submit($form, &$form_state){
  //简单的重定向到contactus页面
 if(empty($_SESSION['chuziren_geren_edit_form'])){
		  //drupal_goto('contact');
		  $form_state['redirect'] = 'chuziren/fundlist';
	  }else{
		  $values = $_SESSION['chuziren_geren_edit_form'];
		  unset($_SESSION['chuziren_geren_edit_form']);
		  db_delete('chuziren_geren_info')
			->condition('id' ,$values['bid'])
			->execute();
		  $form_state['redirect'] = 'chuziren/fundlist';;
	  }

}

//基金管理目录基金选择入口
function jijingguanli_fundlist_page() {
 $html = '';
 //$html.= l('创建基金','guidingfund/create').'<br><br>';
 //$html .= '投后管理阶段：';
 drupal_set_title('基金基本信息');
 $header = array(
      array('data' => '基金名称', 'field' => 'registered_name', 'sort' => 'desc'),
      array('data' => '负责人', 'field' => 'contact'),
      array('data' => '出资人管理'),
      array('data' => '资本到位管理'),
      );
  $query = db_select('fund_basic_information', 'n')
      ->extend('PagerDefault') //Pager Extender
      ->limit(15)//10 results per page
      ->extend('TableSort')//Sorting Extender
      ->orderByHeader($header)//Field to sort on is picked from $header
      ->fields ('n', array (
      'id',
      'registered_name',
      'contact',
      ));
	  
  $results = $query
      ->execute();

  $rows = array();
  foreach ($results as $node) {
		  $rows[] = array(
	      'data' => array(
	        l($node->registered_name, 'fund_basic_information/view/'. $node->id),
	        $node->contact,
	        l('出资人管理', 'chuziren/fundlist/'.$node->id),
	        l('资本到位管理', 'zibendaowei/jilu/ren_fund/'.$node->id),
	        //l('重大事项管理', 'zhongdashixiang_file/fundlist/'.$node->id),
	      )
	      );
  }
  $html .= theme('table', 
      array(
            'header' => $header,
            'rows'=>$rows,
            //'caption' => '反馈意见列表',//Optional Caption for the table
            'sticky' => TRUE,//Optional to indicate whether the table headers should be sticky
            'empty' => '没有基金信息',//Optional empty text for the table if resultset is empty
      )
      );
  $html .= theme('pager',
      array(
            'tags' => array()
      )
      );
  

  return ($html); 
}

//基金管理目录基金选择入口
function jijingguanli_manage_fundlist_page() {
 		$html = '';
 		global $user;
        $failed = 1;
    // 如果没有通过尽调审批，则不开放此功能
        $authquery = db_select('nishejijin', 'n')
            ->fields ('n', array (
                'id',
                'state',
            ))
            ->condition('user_id',$user->uid,'=');
        $authresults = $authquery
        ->execute();
        foreach ($authresults as $node) {
            if ($node->state >= 7) {
                $failed = 0;
            }
        }
        if ($failed == 1) {
            drupal_goto('jijingguanli_manage/fail');
        }
		$query = "SELECT fund_id FROM {fund_basic_information} WHERE user_id = ?";
		$query_result = db_query($query,array($user->uid));
		$result_values = '';
		$fund_id = "";
		foreach ($query_result as $result_values ) {
			$fund_id = $result_values->fund_id;
		}
	    $header = array(
	      array('data' => '基金名称', 'field' => 'registered_name', 'sort' => 'desc'),
	      array('data' => '联系人', 'field' => 'contact'),
	      array('data' => '出资人管理'),
	      array('data' => '资本到位管理'),
	      //array('data' => '重大事项管理'),
      );
  $query = db_select('fund_basic_information', 'n')
      ->extend('PagerDefault') //Pager Extender
      ->limit(15)//10 results per page
      ->extend('TableSort')//Sorting Extender
      ->orderByHeader($header)//Field to sort on is picked from $header
      ->fields ('n', array (
      'id',
      'registered_name',
      'contact',
      ))
	  ->condition('id',$fund_id,'=');
  $results = $query
      ->execute();

  $rows = array();
  foreach ($results as $node) {
		  $rows[] = array(
	      'data' => array(
	        l($node->registered_name, 'fund_basic_information/view/'. $node->id),
	        $node->contact,
	        l('出资人管理', 'chuziren/fundlist/'),
	        l('资本到位管理', 'zibendaowei/jilu/ren_fund/'.$node->id),
	      )
	      );
  }
  $html .= theme('table', 
      array(
            'header' => $header,
            'rows'=>$rows,
            //'caption' => '反馈意见列表',//Optional Caption for the table
            'sticky' => TRUE,//Optional to indicate whether the table headers should be sticky
            'empty' => '没有基金信息',//Optional empty text for the table if resultset is empty
      )
      );
  $html .= theme('pager',
      array(
            'tags' => array()
      )
      );
	    return ($html); 
}

function jijingguanli_manage_fail_page() {
    $html = '';
    $html .= '<div>对不起，您申报的基金尚在审批中（或者您没有申报任何基金），暂时无法使用基金管理功能</div>';
    return $html;
}

/**
 * 会议管理
 */
//传人基金id（基金基本信息表）
function huiyijilu_create_gudong($fund_id){
	  //我们为这个页面设置标题
	 drupal_set_title('新增会议信息');
	 $page_content = l('查看会议记录列表','huiyijilu/fundlist/'.$fund_id) . '<br />'. '<br />';
	 $query = "SELECT id, registered_name FROM " .
           "{fund_basic_information} where id = ?";
	  $queryResult = db_query($query, array($fund_id));
	  foreach($queryResult as $result){
	  	$page_content .= '当前基金：' . '&nbsp;&nbsp;'. $result->registered_name.'<br><br>';
	  }
	 $render_array = array(
	   '#markup' => $page_content, 
	 );
	 
	 $form = drupal_get_form('huiyijilu_form',$fund_id, 1);
	 $render_array['#markup'] .= drupal_render($form);
	 
	 return $render_array;
}

function huiyijilu_create_dongshihui($fund_id){
	  //我们为这个页面设置标题
	 drupal_set_title('新增会议信息');
	 $page_content = l('查看会议记录列表','huiyijilu/fundlist/'.$fund_id) . '<br />'. '<br />';
	 $query = "SELECT id, registered_name FROM " .
           "{fund_basic_information} where id = ?";
	  $queryResult = db_query($query, array($fund_id));
	  foreach($queryResult as $result){
	  	$page_content .= '当前基金：' . '&nbsp;&nbsp;'. $result->registered_name.'<br><br>';
	  }
	 $render_array = array(
	   '#markup' => $page_content, 
	 );
	 
	 $form = drupal_get_form('huiyijilu_form',$fund_id, 2);
	 $render_array['#markup'] .= drupal_render($form);
	 
	 return $render_array;
}

function huiyijilu_create_jianshihui($fund_id){
	  //我们为这个页面设置标题
	 drupal_set_title('新增会议信息');
	 $page_content = l('查看会议记录列表','huiyijilu/fundlist/'.$fund_id) . '<br />'. '<br />';
	 $query = "SELECT id, registered_name FROM " .
           "{fund_basic_information} where id = ?";
	  $queryResult = db_query($query, array($fund_id));
	  foreach($queryResult as $result){
	  	$page_content .= '当前基金：' . '&nbsp;&nbsp;'. $result->registered_name.'<br><br>';
	  }
	 $render_array = array(
	   '#markup' => $page_content, 
	 );
	 
	 $form = drupal_get_form('huiyijilu_form',$fund_id, 3);
	 $render_array['#markup'] .= drupal_render($form);
	 
	 return $render_array;
}

function huiyijilu_form($form, &$form_state, $fund_id, $huiyi_type){
	 $form['bid'] = array('#type' => 'hidden', '#value' => $fund_id);
	 $form['huiyi_type'] = array('#type' => 'hidden', '#value' => $huiyi_type);
	 
	 $form['tips'] = array(
	  '#prefix' =>'<div id="tips">',
	  '#markup' => t('<span class="form-required">*</span> 号为必填项。'),
	  '#suffix' =>'</div>',
	 );
	 
	 $form['huiyi_place'] = array(
	  '#title' => t('会议地点'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['huiyijilu_form']['huiyi_place'])?$_SESSION['huiyijilu_form']['huiyi_place']:"",
	 );
	  $form['huiyi_people'] = array(
	  '#title' => t('参加人员'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['huiyijilu_form']['huiyi_people'])?$_SESSION['huiyijilu_form']['huiyi_people']:"",
	 );
	  $today = getdate();

      $form['timestamp'] = array(
	     '#type' => 'date', // types 'date_popup', 'date_text' and 'date_timezone' are also supported. See .inc file.
	     '#title' => t('会议时间'),
	     '#default_value' => array('year' =>  $today['year'], 'month' =>  $today['mon'], 'day' => $today['mday']), 
	  );
	  
	 $form['huiyi_content'] = array(
	  '#title' => t('会议内容'),
	  '#type' => 'textarea',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['huiyijilu_form']['huiyi_content'])?$_SESSION['huiyijilu_form']['huiyi_content']:"",
	 );

  	 $form['huiyi_result'] = array(
	  '#title' => t('决议事项及结果'),
	  '#type' => 'textarea',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['huiyijilu_form']['huiyi_result'])?$_SESSION['huiyijilu_form']['huiyi_result']:"",
	 );
	 
	 $form['remark'] = array(
	  '#title' => t('备注'),
	  '#type' => 'textarea',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['huiyijilu_form']['remark'])?$_SESSION['huiyijilu_form']['remark']:"",
	 );
	
	  $form['submit'] = array(
	    '#type' => 'submit',
	    '#value' => t('确认'),
	  );
	  return $form;
}

function huiyijilu_form_validate($form, &$form_state){
	  
}

function huiyijilu_form_submit($form, &$form_state){
	  //把表单的值存放在会话中去，由于这里涉及到了两个不同的表单之间传值。
	 $_SESSION['huiyijilu_form'] = $form_state['values'];
	 //表单重定向到确认页面
	 $form_state['redirect'] = 'huiyijilu/confirm';
}
 
function huiyijilu_confirm_page(){
  //我们为这个页面设置标题
	 drupal_set_title('新增会议记录');
	 
	 //这里首先作了判断，如果会话中没有设置contactus_form，返回contactus
	 if(empty($_SESSION['huiyijilu_form'])){
	  drupal_goto('huiyijilu/fundlist');
	 }	
	 $render_array = array(
	   '#markup' => '', 
	 );
	 //该页面的正文为一个表单，注意对于表单，这里需要使用drupal_render呈现一下。
	 $form = drupal_get_form('huiyijilu_confirm_form');
	 $render_array['#markup'] .= drupal_render($form);
	 //Drupal7的页面回调，返回的应该是一个数组
	 return $render_array;
}

function huiyijilu_confirm_form(){
 
	 $form['huiyi_place'] = array(
	  '#title' => t('会议地点'),
	  '#type' => 'item',
	  '#markup' =>isset($_SESSION['huiyijilu_form']['huiyi_place'])?$_SESSION['huiyijilu_form']['huiyi_place']:"",
	 );
	  $form['huiyi_people'] = array(
	  '#title' => t('参加人员'),
	  '#type' => 'item',
	  '#markup' =>isset($_SESSION['huiyijilu_form']['huiyi_people'])?$_SESSION['huiyijilu_form']['huiyi_people']:"",
	 );
	 $datetime = $_SESSION['huiyijilu_form']['timestamp'];

	 $form['timestamp'] = array(
	  '#title' => t('会议时间'),
	  '#type' => 'item',
	  '#markup' => isset($_SESSION['huiyijilu_form']['timestamp'])?$datetime['year'].'年'.$datetime['month'].'月'.$datetime['day'].'日':"",
	 );
		  
	 $form['huiyi_content'] = array(
	  '#title' => t('会议内容'),
	  '#type' => 'item',
	  '#markup' =>isset($_SESSION['huiyijilu_form']['huiyi_content'])?$_SESSION['huiyijilu_form']['huiyi_content']:"",
	 );

  	 $form['huiyi_result'] = array(
	  '#title' => t('决议事项及结果'),
	  '#type' => 'item',
	  '#markup' =>isset($_SESSION['huiyijilu_form']['huiyi_result'])?$_SESSION['huiyijilu_form']['huiyi_result']:"",
	 );
	 
	 $form['remark'] = array(
	  '#title' => t('备注'),
	  '#type' => 'item',
	  '#markup' =>isset($_SESSION['huiyijilu_form']['remark'])?$_SESSION['huiyijilu_form']['remark']:"",
	 );

	  $form['back'] = array(
	    '#type' => 'submit',
	    '#value' => t('返回'),
	    '#submit' => array('huiyijilu_confirm_form_back'),
	  );
	
	  $form['submit'] = array(
	    '#type' => 'submit',
	    '#value' => t('确认提交'),
	  );
  
  	return $form;
}

function huiyijilu_confirm_form_back($form, &$form_state){
 $form_state['redirect'] = 'huiyijilu/create/'.$_SESSION['huiyijilu_form']['bid'];
}

function huiyijilu_confirm_form_submit($form, &$form_state){
		/**
	   * 写入数据库
	   */
	   $values = NULL;
	  if(empty($_SESSION['huiyijilu_form'])){
		  drupal_goto('huiyijilu/create/'.$values['bid']);
	  }else{
		  $values = $_SESSION['huiyijilu_form'];
		  unset($_SESSION['huiyijilu_form']);
	  }
      $datetime = mktime(0, 0, 0,$values['timestamp']['month'], $values['timestamp']['day'], $values['timestamp']['year']);
	  $last_id = db_insert('huiyijilu_info')
  		->fields(array(
  		     'fund_id' => $values['bid'],
   			 'huiyi_type' => $values['huiyi_type'],
   			 'huiyi_place' => $values['huiyi_place'],
   			 'huiyi_people' => $values['huiyi_people'],
   			 'huiyi_content' => $values['huiyi_content'],
   			 'timestamp' =>  $datetime,
   			 'huiyi_result' => $values['huiyi_result'],
   			 'remark' => $values['remark'],
  			))->execute();
	  if ($last_id!=NULL) {
		 $form_state['redirect'] = 'huiyijilu/list/'.$last_id;
	  } else {
	    
	    // 数据写入失败了
	    drupal_set_message('抱歉，遇到问题，提交失败了', 'error');
	    
	  }	
}

//传人基金id
function huiyijilu_gudonglist_perpage($fund_id) {
  $html = l('返回基金列表','huiyijilu/fundlist') . '<br><br>';  

  $query = "SELECT id, registered_name FROM " .
           "{fund_basic_information} where id = ?";
  $queryResult = db_query($query, array($fund_id));
  foreach($queryResult as $result){
  	$html .= '当前基金：' . '&nbsp;&nbsp;'. $result->registered_name.'<br><br>';
  }
  $html .= '<div id="printable_div">';
  $round_num = 1;
  $header = array(
      array('data' => '序号'),
      array('data' => '会议时间', 'field' => 'timestamp'),
      array('data' => '详情', 'field' => 'more'),
      );
  $query = db_select('huiyijilu_info', 'n')
      ->extend('PagerDefault') //Pager Extender
      ->limit(20)//20 results per page
      ->extend('TableSort')//Sorting Extender
      ->orderByHeader($header)//Field to sort on is picked from $header
      ->fields ('n', array (
      'id',
      'timestamp',
      ))
	  ->condition('fund_id',$fund_id,'=')
	  ->condition('huiyi_type',1,'=');
  $results = $query
      ->execute();

  $rows = array();
  $_serial_num = 1;
  foreach ($results as $node) {
  	$datetime = format_date($node->timestamp, 'custom', 'Y-m-d');  
      $rows[] = array(
      'data' => array(
        $_serial_num,
        $datetime,
         l('查看', 'huiyijilu/list/'. $node->id),
      )
      );
	  $_serial_num +=1;
  }
  $html .= theme('table', 
      array(
            'header' => $header,
            'rows'=>$rows,
            //'caption' => '反馈意见列表',//Optional Caption for the table
            'sticky' => TRUE,//Optional to indicate whether the table headers should be sticky
            'empty' => '没有会议记录',//Optional empty text for the table if resultset is empty
      )
      );
  $html .= '</div>';
  $html .= theme('pager',
      array(
            'tags' => array()
      )
      );
  
  return ($html); 
}

//传人基金id
function huiyijilu_dongshihuilist_perpage($fund_id) {
  $html = l('返回基金列表','huiyijilu/fundlist') . '<br><br>';  

  $query = "SELECT id, registered_name FROM " .
           "{fund_basic_information} where id = ?";
  $queryResult = db_query($query, array($fund_id));
  foreach($queryResult as $result){
  	$html .= '当前基金：' . '&nbsp;&nbsp;'. $result->registered_name.'<br><br>';
  }
  $html .= '<div id="printable_div">';
  $round_num = 1;
  $header = array(
      array('data' => '序号'),
      array('data' => '会议时间', 'field' => 'timestamp'),
      array('data' => '详情', 'field' => 'more'),
      );
  $query = db_select('huiyijilu_info', 'n')
      ->extend('PagerDefault') //Pager Extender
      ->limit(20)//20 results per page
      ->extend('TableSort')//Sorting Extender
      ->orderByHeader($header)//Field to sort on is picked from $header
      ->fields ('n', array (
      'id',
      'timestamp',
      ))
	  ->condition('fund_id',$fund_id,'=')
	  ->condition('huiyi_type',2,'=');
  $results = $query
      ->execute();

  $rows = array();
  $_serial_num = 1;
  foreach ($results as $node) {
  	$datetime = format_date($node->timestamp, 'custom', 'Y-m-d');  
      $rows[] = array(
      'data' => array(
        $_serial_num,
        $datetime,
         l('查看', 'huiyijilu/list/'. $node->id),
      )
      );
	  $_serial_num +=1;
  }
  $html .= theme('table', 
      array(
            'header' => $header,
            'rows'=>$rows,
            //'caption' => '反馈意见列表',//Optional Caption for the table
            'sticky' => TRUE,//Optional to indicate whether the table headers should be sticky
            'empty' => '没有会议记录',//Optional empty text for the table if resultset is empty
      )
      );
  $html .= '</div>';
  $html .= theme('pager',
      array(
            'tags' => array()
      )
      );
  
  return ($html); 
}

//传人基金id
function huiyijilu_jianshihuilist_perpage($fund_id) {
  $html = l('返回基金列表','huiyijilu/fundlist') . '<br><br>';  

  $query = "SELECT id, registered_name FROM " .
           "{fund_basic_information} where id = ?";
  $queryResult = db_query($query, array($fund_id));
  foreach($queryResult as $result){
  	$html .= '当前基金：' . '&nbsp;&nbsp;'. $result->registered_name.'<br><br>';
  }
  $html .= '<div id="printable_div">';
  $round_num = 1;
  $header = array(
      array('data' => '序号'),
      array('data' => '会议时间', 'field' => 'timestamp'),
      array('data' => '详情', 'field' => 'more'),
      );
  $query = db_select('huiyijilu_info', 'n')
      ->extend('PagerDefault') //Pager Extender
      ->limit(20)//20 results per page
      ->extend('TableSort')//Sorting Extender
      ->orderByHeader($header)//Field to sort on is picked from $header
      ->fields ('n', array (
      'id',
      'timestamp',
      ))
	  ->condition('fund_id',$fund_id,'=')
	  ->condition('huiyi_type',3,'=');
  $results = $query
      ->execute();

  $rows = array();
  $_serial_num = 1;
  foreach ($results as $node) {
  	$datetime = format_date($node->timestamp, 'custom', 'Y-m-d');  
      $rows[] = array(
      'data' => array(
        $_serial_num,
        $datetime,
         l('查看', 'huiyijilu/list/'. $node->id),
      )
      );
	  $_serial_num +=1;
  }
  $html .= theme('table', 
      array(
            'header' => $header,
            'rows'=>$rows,
            //'caption' => '反馈意见列表',//Optional Caption for the table
            'sticky' => TRUE,//Optional to indicate whether the table headers should be sticky
            'empty' => '没有会议记录',//Optional empty text for the table if resultset is empty
      )
      );
  $html .= '</div>';
  $html .= theme('pager',
      array(
            'tags' => array()
      )
      );
  
  return ($html); 
}

//传人会议记录id
function huiyijilu_per_page($perid) {
 
  // content variable that will be returned for display
  $page_content = '';

  drupal_set_title('会议记录详情');
	 
  $query = "SELECT fund_id,huiyi_type,huiyi_place,huiyi_people,huiyi_content,huiyi_result,timestamp,remark FROM " .
           "{huiyijilu_info} where id = ?";
  $queryResult = db_query($query, array($perid));
  $company_name = '';
  $huiyi_type = '';
  $huiyi_place = '';
  $huiyi_people = '';
  $huiyi_content = '';
  $huiyi_result = '';
  $datetime = '';
  $remark = '';
  $fund_id = '';

  foreach ($queryResult as $links ) {
  	$fund_id = $links->fund_id;
  	$datetime = format_date($links->timestamp, 'custom', 'Y-m-d'); 
    $huiyi_type = $links->huiyi_type;
    $huiyi_place = $links->huiyi_place;
    $huiyi_content = $links->huiyi_content;
    $huiyi_result = $links->huiyi_result;
    $huiyi_people = $links->huiyi_people;
    $remark = $links->remark;
  }
  
  $query = "SELECT id, registered_name FROM " .
           "{fund_basic_information} where id = ?";
  $queryResult = db_query($query, array($fund_id));
  foreach($queryResult as $result){
  	$company_name = $result->registered_name;
  }
  
  $html = "";
  if( user_access('jijingguanligongsi manage'))
  	 $html .= l('返回会议列表','huiyijilu/type/'.$huiyi_type) . '<br />'. '<br />'; 
  else{
  	if($huiyi_type == 1)
  		 $html .= l('返回会议列表','huiyijilu/gudonglist/'.$fund_id) . '<br />'. '<br />';
	else if($huiyi_type == 2)
  		 $html .= l('返回会议列表','huiyijilu/dongshihuilist/'.$fund_id) . '<br />'. '<br />'; 
	else if($huiyi_type == 3)
  		 $html .= l('返回会议列表','huiyijilu/jianshihuilist/'.$fund_id) . '<br />'. '<br />'; 
  }
  
   if($huiyi_type == 1)
  		 $huiyi_type = "股东会/合伙人大会";
	else if($huiyi_type == 2)
  		 $huiyi_type = "董事会";
	else if($huiyi_type == 3)
	 	 $huiyi_type = "监事会";
  $html .= "<table style='width: 500px'><tr><th colspan=2>".$company_name."  ".$huiyi_type." 会议情况</th></tr>
  <tr><td style='width: 40%'>会议时间</td><td>".$datetime."</td></tr>
  <tr><td>会议地点</td><td>".$huiyi_place."</td></tr>
  <tr><td>参加人员</td><td>".$huiyi_people."</td></tr>
  <tr><td>会议内容</td><td>".$huiyi_content."</td></tr>
  <tr><td>决议事项及结果</td><td>".$huiyi_result."</td></tr>
  <tr><td>备注</td><td>".$remark."</td></tr></table>";
  
	 
	 //Drupal7的页面回调，返回的应该是一个数组
  return $html;
}


//传人会议记录id
function huiyijilu_edit_page($perid) {
 
  // content variable that will be returned for display
  $page_content = '';
  $page_content .= l('返回基金列表','huiyijilu/fundlist') . '<br />'. '<br />';  
  drupal_set_title('管理该项会议记录');
	 
  $render_array = array(
	   '#markup' => $page_content,
	 );
	 
	 //该页面的正文为一个表单，注意对于表单，这里需要使用drupal_render呈现一下。
  $form = drupal_get_form('huiyijilu_edit_form',$perid);
  $render_array['#markup'] .= drupal_render($form);
	 
	 //Drupal7的页面回调，返回的应该是一个数组
  return $render_array;
}

function huiyijilu_edit_form($form, &$form_state, $perid){
  $query = "SELECT huiyi_place,huiyi_people,huiyi_content,huiyi_result,timestamp,remark FROM " .
           "{huiyijilu_info} where id = ?";
  $queryResult = db_query($query, array($perid));
  $huiyi_place = '';
  $huiyi_people = '';
  $huiyi_content = '';
  $huiyi_result = '';
  $datetime = '';
  $remark = '';

  foreach ($queryResult as $links ) {
  	$datetime = getdate($links->timestamp);
    $huiyi_place = $links->huiyi_place;
    $huiyi_content = $links->huiyi_content;
    $huiyi_result = $links->huiyi_result;
    $huiyi_people = $links->huiyi_people;
    $remark = $links->remark;
  }
  // More coming....
  if ($queryResult == '') {
    $form = NULL;
  }
  else{
   $form['bid'] = array('#type' => 'hidden', '#value' => $perid);
	 $form['huiyi_place'] = array(
	  '#title' => t('会议地点'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['huiyijilu_form']['huiyi_place'])?$_SESSION['huiyijilu_form']['huiyi_place']:$huiyi_place,
	 );
	  $form['huiyi_people'] = array(
	  '#title' => t('参加人员'),
	  '#type' => 'textfield',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['huiyijilu_form']['huiyi_people'])?$_SESSION['huiyijilu_form']['huiyi_people']:$huiyi_people,
	 );
	 
	 $form['timestamp'] = array(
	   '#type' => 'date', // types 'date_popup', 'date_text' and 'date_timezone' are also supported. See .inc file.
	   '#title' => t('成立时间'),
	   '#default_value' => isset($_SESSION['chuziren_form']['timestamp'])?$_SESSION['chuziren_form']['timestamp']:
		     	array('year' =>  $datetime['year'], 'month' =>  $datetime['mon'], 'day' => $datetime['mday']), 
	 );
		  
	 $form['huiyi_content'] = array(
	  '#title' => t('会议内容'),
	  '#type' => 'textarea',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['huiyijilu_form']['huiyi_content'])?$_SESSION['huiyijilu_form']['huiyi_content']:$huiyi_content,
	 );

  	 $form['huiyi_result'] = array(
	  '#title' => t('决议事项及结果'),
	  '#type' => 'textarea',
	  '#required' => TRUE,
	  '#default_value' =>isset($_SESSION['huiyijilu_form']['huiyi_result'])?$_SESSION['huiyijilu_form']['huiyi_result']:$huiyi_result,
	 );
	 
	 $form['remark'] = array(
	  '#title' => t('备注'),
	  '#type' => 'textarea',
	  '#required' => FALSE,
	  '#default_value' =>isset($_SESSION['huiyijilu_form']['remark'])?$_SESSION['huiyijilu_form']['remark']:$remark,
	 );
	  $form['submit'] = array(
	    '#type' => 'submit',
	    '#value' => t('提交修改'),
	  );
	  
	 //表单元素“提交”按钮
	  $form['deleate'] = array(
	    '#type' => 'submit',
	    '#value' => t('删除该会议记录'),
	    '#submit' => array('huiyijilu_edit_form_deleate'),
	  );
  	
  }
  
  return $form;
}

function huiyijilu_edit_form_submit($form, &$form_state){
	  $values = NULL;
	  $values = $form_state['values'];
      $datetime = mktime(0, 0, 0,$values['timestamp']['month'], $values['timestamp']['day'], $values['timestamp']['year']);
	  db_update('huiyijilu_info')
  		->fields(array(
   			 'huiyi_place' => $values['huiyi_place'],
   			 'huiyi_people' => $values['huiyi_people'],
   			 'huiyi_content' => $values['huiyi_content'],
   			 'timestamp' =>  $datetime,
   			 'huiyi_result' => $values['huiyi_result'],
   			 'remark' => $values['remark'],
  			))
  		->condition('id', $values['bid'])
  		->execute();
	 $form_state['redirect'] = 'huiyijilu/list/'.$values['bid'];
}

function huiyijilu_edit_form_deleate($form, &$form_state){
	 $values = NULL;
	 $_SESSION['huiyijilu_edit_form'] = $form_state['values'];
	 $values = $_SESSION['huiyijilu_edit_form'] ;
	 //表单重定向到确认页面
	 $form_state['redirect'] = 'huiyijilu/deleate/'.$values['bid'];
}

function huiyijilu_deleate_page($perid) {
  // content variable that will be returned for display
  $page_content = '删除后该会议记录将不可恢复！';
  
  drupal_set_title('删除该会议记录');
	 
	 $render_array = array(
	   '#markup' => $page_content,
	 );
	 
	 //该页面的正文为一个表单，注意对于表单，这里需要使用drupal_render呈现一下。
	 $form = drupal_get_form('huiyijilu_deleate_form');
	 $render_array['#markup'] .= drupal_render($form);
	 
	 //Drupal7的页面回调，返回的应该是一个数组
  return $render_array;

}

function huiyijilu_deleate_form($form, &$form_state){
 //表单元素“返回”按钮
  $form['back'] = array(
    '#type' => 'submit',
    '#value' => t('取消'),
    '#submit' => array('huiyijilu_deleate_form_back'),
  );
 //表单元素“提交”按钮
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('删除'),
  );
  
  return $form;
}

function huiyijilu_deleate_form_back($form, &$form_state){
	if(empty($_SESSION['huiyijilu_edit_form'])){
		  //drupal_goto('contact');
		  $form_state['redirect'] = 'huiyijilu/fundlist';
	  }else{
		  $values = $_SESSION['huiyijilu_edit_form'];
		  unset($_SESSION['huiyijilu_edit_form']);
		  $form_state['redirect'] = 'huiyijilu/list/'.$values['bid'];
	  }
}

function huiyijilu_deleate_form_submit($form, &$form_state){
  //简单的重定向到contactus页面
 if(empty($_SESSION['huiyijilu_edit_form'])){
		  //drupal_goto('contact');
		  $form_state['redirect'] = 'huiyijilu/fundlist';
	  }else{
		  $values = $_SESSION['huiyijilu_edit_form'];
		  unset($_SESSION['huiyijilu_edit_form']);
		  db_delete('huiyijilu_info')
			->condition('id' ,$values['bid'])
			->execute();
		  $form_state['redirect'] = 'huiyijilu/fundlist';;
	  }

}

function huiyijilu_fund_page(){
  global $user;
  $query = "SELECT id, registered_name FROM " .
           "{fund_basic_information} where user_id = ?";
  $queryResult = db_query($query, array($user->uid));
  $fund_id =0;
  $html = "";
  $registered_name = "";
  foreach($queryResult as $result){
	$fund_id = $result->id;
	$registered_name =  $result->registered_name;
  }

  $round_num = 1;
  $header = array(
      array('data' => '基金注册名称'),
      array('data' => '股东会/合伙人大会'),
      array('data' => '董事会'),
      array('data' => '监事会'),
      );

	  $rows[] = array(
      'data' => array(
        $registered_name,
         l('查看', 'huiyijilu/type/1'),
         l('查看', 'huiyijilu/type/2'),
         l('查看', 'huiyijilu/type/3'),
      )
      );
    $html .= theme('table', 
      array(
            'header' => $header,
            'rows'=>$rows,
            //'caption' => '反馈意见列表',//Optional Caption for the table
            'sticky' => TRUE,//Optional to indicate whether the table headers should be sticky
            'empty' => '没有会议记录',//Optional empty text for the table if resultset is empty
      )
      );
  $html .= '</div>';
  $html .= theme('pager',
      array(
            'tags' => array()
      )
      );
  
  return ($html); 
}


function huiyijilu_type_page($type){
  global $user;
  $query = "SELECT id, registered_name FROM " .
           "{fund_basic_information} where user_id = ?";
  $queryResult = db_query($query, array($user->uid));
  $fund_id =0;
  $html = "";
  $registered_name = "";
  foreach($queryResult as $result){
	$fund_id = $result->id;
	$registered_name =  $result->registered_name;
  }
  $html .= l('返回','huiyijilu/fund') . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';  
  if($type == 1)
  	$html .= l('添加会议记录','huiyijilu/create_gudong/'.$fund_id) . '<br>';
  else if($type == 2)
  	$html .= l('添加会议记录','huiyijilu/create_dongshihui/'.$fund_id) . '<br>';
  else if($type == 3)
  	$html .= l('添加会议记录','huiyijilu/create_jianshihui/'.$fund_id) . '<br>';

  $round_num = 1;
  $header = array(
      array('data' => '序号'),
      array('data' => '基金注册名称'),
      array('data' => '会议时间', 'field' => 'timestamp'),
      array('data' => '详情'),
      );
  
  $query = "SELECT id,timestamp FROM " .
           "{huiyijilu_info} where fund_id = ? and huiyi_type =? ";
  $queryResult = db_query($query, array($fund_id,$type));
  $rows = array();
  foreach($queryResult as $node){
	  $_serial_num = 1;
	  $datetime = format_date($node->timestamp, 'custom', 'Y-m-d');
	  $rows[] = array(
	      'data' => array(
	        $_serial_num,
	        $registered_name,
	        $datetime,
	         l('查看', 'huiyijilu/list/'. $node->id),
	      )
	  );
	  $_serial_num += 1;
  }

 
  $html .= theme('table', 
      array(
            'header' => $header,
            'rows'=>$rows,
            //'caption' => '反馈意见列表',//Optional Caption for the table
            'sticky' => TRUE,//Optional to indicate whether the table headers should be sticky
            'empty' => '没有会议记录',//Optional empty text for the table if resultset is empty
      )
      );
  $html .= '</div>';
  $html .= theme('pager',
      array(
            'tags' => array()
      )
      );
  
  return ($html); 
}


//出资人设置基金选择入口
function huiyijilu_fundlist_page() {
 $html = '';

 if(user_access('jijingguanligongsi manage')){
 	drupal_goto('huiyijilu/fund');
 }
 $header = array(
 	  array('data' => '序号'),
      array('data' => '基金名称', 'field' => 'registered_name', 'sort' => 'desc'),
      array('data' => '股东会/合伙人大会'),
      array('data' => '董事会'),
      array('data' => '监事会'),
      );
  $query = db_select('fund_basic_information', 'n')
      ->extend('PagerDefault') //Pager Extender
      ->limit(15)//10 results per page
      ->extend('TableSort')//Sorting Extender
      ->orderByHeader($header)//Field to sort on is picked from $header
      ->fields ('n', array (
      'id',
      'registered_name',
      'contact',
      ));
  $results = $query
      ->execute();

  $rows = array();
  $_serial_num = 1;
  foreach ($results as $node) {
  	 
		  $rows[] = array(
	      'data' => array(
	        $_serial_num,
	        $node->registered_name,
	         l('查看', 'huiyijilu/gudonglist/'. $node->id),
	         l('查看', 'huiyijilu/dongshihuilist/'. $node->id),
	         l('查看', 'huiyijilu/jianshihuilist/'. $node->id),
	      )
	      );
		  $_serial_num +=1;
  }
  $html .= theme('table', 
      array(
            'header' => $header,
            'rows'=>$rows,
            //'caption' => '反馈意见列表',//Optional Caption for the table
            'sticky' => TRUE,//Optional to indicate whether the table headers should be sticky
            'empty' => '没有基金信息',//Optional empty text for the table if resultset is empty
      )
      );
  $html .= theme('pager',
      array(
            'tags' => array()
      )
      );
  return ($html); 
}

